Skip to content

Commit

Permalink
Add source "hackernews"
Browse files Browse the repository at this point in the history
  • Loading branch information
telotortium committed Apr 15, 2022
1 parent ba333c7 commit 22c529a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/promnesia/sources/hackernews.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'''
Uses [[https://github.com/karlicoss/HPI][HPI]] dogsheep module to import
Hacker News items.
'''

import textwrap

from promnesia.common import Visit, Loc, Results


def index() -> Results:
from . import hpi
from my.hackernews import dogsheep

for item in dogsheep.items():
hn_url = item.permalink()
title = "hackernews"
if item.title:
title = item.title
elif item.text_html:
title = item.text_html
title = textwrap.shorten(
title, width=79, placeholder="…",
break_long_words=True)
# The locator is always the HN story. If the story is a link (as
# opposed to a text post), we insert a visit such that the link
# will point back to the corresponding HN story.
loc = Loc.make(title=title, href=hn_url)
urls = [hn_url]
if item.url is not None:
urls.append(item.url)
for url in urls:
yield Visit(
url=url,
dt=item.created,
locator=loc,
context=title,
)

0 comments on commit 22c529a

Please sign in to comment.