diff --git a/my/reading/polar.py b/my/reading/polar.py index a38662d..5b2ecae 100755 --- a/my/reading/polar.py +++ b/my/reading/polar.py @@ -19,13 +19,14 @@ if user_config is None: pass +from ..core import PathIsh from dataclasses import dataclass @dataclass class polar(user_config): ''' Polar config is optional, you only need it if you want to specify custom 'polar_dir' ''' - polar_dir: Path = Path('~/.polar').expanduser() + polar_dir: PathIsh = Path('~/.polar').expanduser() from ..core import make_config @@ -67,14 +68,19 @@ class Highlight(NamedTuple): Uid = str class Book(NamedTuple): - uid: Uid created: datetime - filename: str + uid: Uid + path: Path title: Optional[str] # TODO hmmm. I think this needs to be defensive as well... # think about it later. items: Sequence[Highlight] + @property + def filename(self) -> str: + # TODO deprecate + return str(self.path) + Result = Res[Book] class Loader: @@ -180,15 +186,18 @@ class Loader: # TODO konsume here as well? di = j['docInfo'] added = di['added'] - filename = di['filename'] + filename = di['filename'] # TODO here title = di.get('title', None) tags = di['tags'] pm = j['pageMetas'] + + path = Path(config.polar_dir) / 'stash' / filename + yield Book( - uid=self.uid, created=isoparse(added), - filename=filename, + uid=self.uid, + path=path, title=title, items=list(self.load_items(pm)), ) diff --git a/tests/extra/polar.py b/tests/extra/polar.py index 1656132..606e32e 100644 --- a/tests/extra/polar.py +++ b/tests/extra/polar.py @@ -11,17 +11,10 @@ import pytest # type: ignore def test_hpi(prepare: str) -> None: - import my.reading.polar as polar - reload(polar) from my.reading.polar import get_entries assert len(list(get_entries())) > 1 - def test_orger(prepare: str, tmp_path: Path) -> None: - import my.reading.polar as polar - reload(polar) - # TODO hmm... ok, need to document reload() - from my.core.common import import_from, import_file om = import_file(ROOT / 'orger/modules/polar.py') # reload(om) @@ -52,4 +45,7 @@ def prepare(request): import my.config setattr(my.config, 'polar', user_config) + import my.reading.polar as polar + reload(polar) + # TODO hmm... ok, need to document reload() yield dotpolar