polar: allow properly specifying polar_dir, with ~ as a default
This commit is contained in:
parent
8f86d7706b
commit
f3d5064ff2
4 changed files with 55 additions and 12 deletions
|
@ -33,6 +33,7 @@ modules = [
|
|||
('twint' , 'my.twitter.twint' ),
|
||||
('twitter', 'my.twitter.archive' ),
|
||||
('lastfm' , 'my.lastfm' ),
|
||||
('polar' , 'my.reading.polar' ),
|
||||
]
|
||||
|
||||
def indent(s, spaces=4):
|
||||
|
@ -117,4 +118,15 @@ for cls, p in modules:
|
|||
"""
|
||||
export_path: Paths
|
||||
#+end_src
|
||||
- [[file:../my/reading/polar.py][my.reading.polar]]
|
||||
|
||||
[[https://github.com/burtonator/polar-books][Polar]] articles and highlights
|
||||
|
||||
#+begin_src python
|
||||
class polar:
|
||||
'''
|
||||
Polar config is optional, you only need it if you want to specify custom 'polar_dir'
|
||||
'''
|
||||
polar_dir: Path = Path('~/.polar').expanduser()
|
||||
#+end_src
|
||||
:end:
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# this file only keeps the most common & critical types/utility functions
|
||||
from .common import PathIsh, Paths, Json
|
||||
from .common import get_files
|
||||
from .common import get_files, LazyLogger
|
||||
from .cfg import make_config
|
||||
|
|
|
@ -1,23 +1,51 @@
|
|||
"""
|
||||
[[https://github.com/burtonator/polar-books][Polar]] articles and highlights
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Type, Any, cast, TYPE_CHECKING
|
||||
|
||||
|
||||
import my.config
|
||||
|
||||
if not TYPE_CHECKING:
|
||||
user_config = getattr(my.config, 'polar', None)
|
||||
else:
|
||||
# mypy can't handle dynamic base classes... https://github.com/python/mypy/issues/2477
|
||||
user_config = object
|
||||
|
||||
# by default, Polar doesn't need any config, so perhaps makes sense to make it defensive here
|
||||
if user_config is None:
|
||||
class user_config: # type: ignore[no-redef]
|
||||
pass
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
from ..core import make_config
|
||||
config = make_config(polar)
|
||||
|
||||
# todo not sure where it keeps stuff on Windows?
|
||||
# https://github.com/burtonator/polar-bookshelf/issues/296
|
||||
|
||||
from datetime import datetime
|
||||
from typing import List, Dict, Iterator, NamedTuple, Sequence, Optional
|
||||
import json
|
||||
|
||||
import pytz
|
||||
|
||||
from ..common import LazyLogger, get_files
|
||||
from ..core import get_files, LazyLogger
|
||||
|
||||
from ..error import Res, echain, unwrap, sort_res_by
|
||||
from ..kython.konsume import wrap, zoom, ignore
|
||||
|
||||
|
||||
_POLAR_DIR = Path('~').expanduser() / '.polar'
|
||||
|
||||
|
||||
logger = LazyLogger(__name__)
|
||||
|
||||
|
||||
|
@ -173,7 +201,7 @@ class Loader:
|
|||
|
||||
|
||||
def iter_entries() -> Iterator[Result]:
|
||||
for d in get_files(_POLAR_DIR, glob='*/state.json'):
|
||||
for d in get_files(config.polar_dir, glob='*/state.json'):
|
||||
loader = Loader(d)
|
||||
try:
|
||||
yield from loader.load()
|
||||
|
|
|
@ -7,18 +7,21 @@ import pytest # type: ignore
|
|||
|
||||
# todo maybe search fot info.json recursively?
|
||||
@pytest.mark.parametrize('dotpolar', [
|
||||
'',
|
||||
'data/polar/BojanKV_polar/.polar',
|
||||
'data/polar/TheCedarPrince_KnowledgeRepository',
|
||||
'data/polar/coelias_polardocs',
|
||||
'data/polar/warkdarrior_polar-document-repository'
|
||||
])
|
||||
def test_hpi(dotpolar: str):
|
||||
if dotpolar != '':
|
||||
pdir = Path(ROOT / dotpolar)
|
||||
class user_config:
|
||||
export_dir = pdir
|
||||
|
||||
import my.config
|
||||
setattr(my.config, 'polar', user_config)
|
||||
|
||||
import sys
|
||||
M = 'my.reading.polar'
|
||||
if M in sys.modules:
|
||||
|
|
Loading…
Add table
Reference in a new issue