conform to updated hypexport

This commit is contained in:
Dima Gerasimov 2019-11-13 00:03:19 +00:00
parent 9f35f0f69b
commit 00693e5e11

View file

@ -10,7 +10,7 @@ def get_model() -> hypexport.Model:
return model return model
Annotation = hypexport.Annotation Highlight = hypexport.Highlight
from typing import Dict, List, NamedTuple, Optional, Sequence from typing import Dict, List, NamedTuple, Optional, Sequence
@ -22,40 +22,40 @@ from .common import group_by_key, the, cproperty
class Page(NamedTuple): class Page(NamedTuple):
""" """
Represents annotated page along with the annotations Represents annotated page along with the highlights
""" """
annotations: Sequence[Annotation] highlights: Sequence[Highlight]
@cproperty @cproperty
def link(self): def link(self):
return the(h.link for h in self.annotations) return the(h.page_link for h in self.highlights)
@cproperty @cproperty
def title(self): def title(self):
return the(h.title for h in self.annotations) return the(h.page_title for h in self.highlights)
@cproperty @cproperty
def dt(self) -> datetime: def dt(self) -> datetime:
return min(h.dt for h in self.annotations) return min(h.dt for h in self.highlights)
def _iter(): def _iter():
yield from get_model().iter_annotations() yield from get_model().iter_highlights()
def get_pages() -> List[Page]: def get_pages() -> List[Page]:
grouped = group_by_key(_iter(), key=lambda e: e.link) grouped = group_by_key(_iter(), key=lambda e: e.page_link)
pages = [] pages = []
for link, group in grouped.items(): for link, group in grouped.items():
sgroup = tuple(sorted(group, key=lambda e: e.dt)) sgroup = tuple(sorted(group, key=lambda e: e.dt))
pages.append(Page(annotations=sgroup)) pages.append(Page(highlights=sgroup))
pages = list(sorted(pages, key=lambda p: p.dt)) pages = list(sorted(pages, key=lambda p: p.dt))
# TODO fixme page tag?? # TODO fixme page tag??
return pages return pages
def get_highlights(): def get_highlights():
return list(_iter()) return list(sorted(_iter(), key=lambda h: h.dt))
def test(): def test():