Skip to content

Commit

Permalink
Support parse jobs posts
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrabbit committed May 14, 2024
1 parent 35050b3 commit 853de12
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hacker_news/llm/openai.py
Expand Up @@ -117,7 +117,7 @@ def call_openai_family(content: str, sys_prompt: str) -> str:
for line in answer.split('\n'):
if not line.strip():
continue
if 'summary' in line.lower() and len(line) <= 100:
if 'summary' in line.lower() and line.strip()[-1] == ':':
continue
answer = line
break
Expand Down
6 changes: 5 additions & 1 deletion hacker_news/news.py
Expand Up @@ -80,6 +80,9 @@ def get_score(self) -> int:
except:
return 0

def is_hiring_job(self) -> bool:
return self.get_score() == 0 and not self.author and 'YC ' in self.title

def slug(self):
return slugify(self.title or 'no title')

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

Expand Down
5 changes: 5 additions & 0 deletions test/test_hackernews_parser.py
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime, timedelta

from hacker_news.algolia_api import get_news
from hacker_news.news import News
from hacker_news.parser import HackerNewsParser


Expand Down Expand Up @@ -52,3 +53,7 @@ def test_algolia_api(self):
date = news_list[0].submit_time.date()
for news in news_list:
self.assertEqual(date, news.submit_time.date())

def test_maybe_jobs_post(self):
news = News(title='MixRank (YC S11) Is Hiring Software Engineers and Founders Globally')
self.assertTrue(news.is_hiring_job())

0 comments on commit 853de12

Please sign in to comment.