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