-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba333c7
commit 22c529a
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |