Skip to content

Commit 853de12

Browse files
committed
Support parse jobs posts
1 parent 35050b3 commit 853de12

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

hacker_news/llm/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def call_openai_family(content: str, sys_prompt: str) -> str:
117117
for line in answer.split('\n'):
118118
if not line.strip():
119119
continue
120-
if 'summary' in line.lower() and len(line) <= 100:
120+
if 'summary' in line.lower() and line.strip()[-1] == ':':
121121
continue
122122
answer = line
123123
break

hacker_news/news.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ def get_score(self) -> int:
8080
except:
8181
return 0
8282

83+
def is_hiring_job(self) -> bool:
84+
return self.get_score() == 0 and not self.author and 'YC ' in self.title
85+
8386
def slug(self):
8487
return slugify(self.title or 'no title')
8588

@@ -130,7 +133,8 @@ def summarize_by_openai(self, content):
130133
if not openai.api_key:
131134
logger.info("OpenAI API key is not set")
132135
return ''
133-
if self.get_score() < config.openai_score_threshold: # Avoid expensive openai
136+
if (self.get_score() < config.openai_score_threshold # Avoid expensive openai
137+
and not self.is_hiring_job()):
134138
logger.info("Score %d is too small, ignore openai", self.get_score())
135139
return ''
136140

test/test_hackernews_parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from datetime import datetime, timedelta
33

44
from hacker_news.algolia_api import get_news
5+
from hacker_news.news import News
56
from hacker_news.parser import HackerNewsParser
67

78

@@ -52,3 +53,7 @@ def test_algolia_api(self):
5253
date = news_list[0].submit_time.date()
5354
for news in news_list:
5455
self.assertEqual(date, news.submit_time.date())
56+
57+
def test_maybe_jobs_post(self):
58+
news = News(title='MixRank (YC S11) Is Hiring Software Engineers and Founders Globally')
59+
self.assertTrue(news.is_hiring_job())

0 commit comments

Comments
 (0)