Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh: harvest URLs from Hypothes.is comments & higleted text #222

Merged
merged 3 commits into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/promnesia/sources/hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
'''
"""
Uses HPI [[https://github.com/karlicoss/HPI/blob/master/doc/MODULES.org#myhypothesis][hypothesis]] module
'''
from ..common import Visit, Results, logger, Loc
"""
from ..common import Loc, Results, Visit, extract_urls


def _harvest_text(text, part_name, visit_base) -> Results:
ankostis marked this conversation as resolved.
Show resolved Hide resolved
if text and text.strip():
urls = extract_urls(text)
for url in urls:
yield visit_base._replace(
url=url,
locator=visit_base.locator._replace(title=f"hypothesis-{part_name}"),
)


def index() -> Results:
from . import hpi
import my.hypothesis as hyp

for h in hyp.get_highlights():
if isinstance(h, Exception):
yield h
Expand All @@ -18,15 +29,23 @@ def index() -> Results:
if hl is not None:
cparts.append(hl)
if ann is not None:
cparts.extend(['comment: ' + ann])
cparts.append(f"comment: {ann}")
if tags:
cparts.append(" ".join(f"#{t}" for t in tags))
yield Visit(
visit = Visit(
url=h.url,
dt=h.created,
context='\n\n'.join(cparts),
context="\n\n".join(cparts),
locator=Loc.make(
title='hypothesis',
title="hypothesis",
href=h.hyp_link,
)
),
)

yield visit

for text, part_name in (
(hl, "highlighted"),
(ann, "comment"),
):
yield from _harvest_text(text, part_name, visit)