polar: expose a proper filename
This commit is contained in:
parent
87ad9d38bb
commit
759b0e1324
2 changed files with 18 additions and 13 deletions
|
@ -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)),
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue