Skip to content
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:
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)