Skip to content

Commit

Permalink
Also add comment url when there are 0 comment
Browse files Browse the repository at this point in the history
  • Loading branch information
polyrabbit committed Jul 2, 2024
1 parent e938b54 commit eb87437
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion hacker_news/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ def parse_news_list(self):
submit_time = self.human2datetime(submit_time)
# In case of no comments yet
comment_dom = subtext_dom.find('a', string=re.compile(r'\d+.+comment')) or Null
discuss_dom = subtext_dom.find('a', string=re.compile(r'discuss')) or Null
comment_cnt = re.search(r'\d+', comment_dom.get_text() or '0').group()
comment_url = self.get_comment_url(comment_dom['href'])
comment_url = self.get_comment_url(comment_dom['href']) or self.get_comment_url(discuss_dom['href'])

items.append(News(
rank=rank,
Expand Down
2 changes: 1 addition & 1 deletion publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def gen_feed(news_list):
(
' <a href="%s" target="_blank">[summary]</a>' % f'{config.site}/#{news.slug()}'),
(
' <a href="%s" target="_blank">[comments]</a>' % news.comment_url if news.comment_url and news.comment_url else '')),
' <a href="%s" target="_blank">[comments]</a>' % news.comment_url if news.comment_url else '')),
author={
'name': news.author,
'uri': news.author_link
Expand Down
4 changes: 2 additions & 2 deletions test/test_html_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ def test_arxiv_content(self):
def test_link_intensive_wikipedia(self):
parser = parser_factory('https://en.wikipedia.org/wiki/Google_Sidewiki')
content = parser.get_content()
self.assertTrue(content.startswith('Google Sidewiki was a web annotation tool from Google'))
self.assertTrue(content.startswith('Google Sidewiki was a web annotation tool from Google'), msg=content[:100])

def test_dynamic_js_page(self):
parser = parser_factory('https://www.science.org/content/article/u-s-wants-change-how-researchers-get-access-huge-trove-health-data-many-don-t-idea')
content = parser.get_content()
self.assertTrue(content.startswith('Health researchers'))
self.assertTrue(content.startswith('Health researchers'), msg=content[:100])

def test_longer_meta_description(self):
html_doc = """
Expand Down

0 comments on commit eb87437

Please sign in to comment.