diff --git a/doc/SETUP.org b/doc/SETUP.org index c2a0fab..1181159 100644 --- a/doc/SETUP.org +++ b/doc/SETUP.org @@ -117,6 +117,13 @@ Generally you can just try using the module and then install missing packages vi * Usage examples If you run your script with ~with_my~ wrapper, you'd have ~my~ in ~PYTHONPATH~ which gives you access to your data from within the script. +** Polar +Polar doesn't require any setup as it accesses the highlights on your filesystem (should be in =~/.polar=). + +You can try if it works with: + +: with_my python3 -c 'import my.reading.polar as polar; print(polar.get_entries())' + ** Kobo reader Kobo provider allows you access the books you've read along with the highlights and notes. It uses exports provided by [[https://github.com/karlicoss/kobuddy][kobuddy]] package. @@ -137,11 +144,13 @@ After that you should be able to use it: #+end_src ** Orger +# TODO include this from orger docs?? + You can use [[https://github.com/karlicoss/orger][orger]] to get Org-mode representations of your data. -Some examples: +Some examples (assuming you've [[https://github.com/karlicoss/orger#installing][installed]] Orger): -*** [[https://github.com/burtonator/polar-bookshelf][Polar]] +*** Orger + [[https://github.com/burtonator/polar-bookshelf][Polar]] This will convert Polar highlights into org-mode: diff --git a/lint b/lint index 3aca624..a936041 100755 --- a/lint +++ b/lint @@ -18,25 +18,22 @@ DIR = Path(__file__).absolute().parent # TODO could reuse in readme?? # returns None if not a package -def package_name(p: Path) -> Optional[str]: +def package_name(p: Path) -> str: def mname(p: Path): nosuf = p.with_suffix('') return str(nosuf).replace('/', '.') - if p.suffix == '.py': + has_init = (p.parent / '__init__.py').exists() + if has_init: + return mname(p.parent) + else: return mname(p) - if p.is_dir() and (p / '__init__.py').exists(): - return mname(p) - - return None - def packages() -> Iterable[str]: - for p in sorted(p.relative_to(DIR) for p in (DIR / 'my').iterdir()): - res = package_name(p) - if res is not None: - yield res + yield from sorted(set( + package_name(p.relative_to(DIR)) for p in (DIR / 'my').rglob('*.py') + )) def pylint(): diff --git a/my/reading/__init__.py b/my/reading/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/my/reading/polar.py b/my/reading/polar.py index e63eab9..2e179cb 100755 --- a/my/reading/polar.py +++ b/my/reading/polar.py @@ -1,36 +1,25 @@ -#!/usr/bin/python3 """ -Module for Polar articles and highlights +[[https://github.com/burtonator/polar-books][Polar]] articles and highlights """ - from pathlib import Path from datetime import datetime -import logging from typing import List, Dict, Iterator, NamedTuple, Sequence, Optional import json import pytz # TODO declare DEPENDS = [pytz??] -from ..common import setup_logger +from ..common import LazyLogger, get_files from ..error import ResT, echain, unwrap, sort_res_by from ..kython.konsume import wrap, zoom, ignore -# TOFO FIXME appdirs?? -_POLAR_DIR = Path('~/.polar') +_POLAR_DIR = Path('~').expanduser() / '.polar' -# TODO FIXME lazylogger?? -def get_logger(): - # TODO __package__? - return logging.getLogger('my.reading.polar') - - -def _get_datas() -> List[Path]: - return list(sorted(_POLAR_DIR.expanduser().glob('*/state.json'))) +logger = LazyLogger(__name__) def parse_dt(s: str) -> datetime: @@ -74,7 +63,7 @@ class Loader: self.path = p self.uid = self.path.parent.name self.err = Error(p) - self.logger = get_logger() + self.logger = logger def error(self, cause, extra=''): return echain(Error(self.path, extra), cause) @@ -185,8 +174,7 @@ class Loader: def iter_entries() -> Iterator[Result]: - logger = get_logger() - for d in _get_datas(): + for d in get_files(_POLAR_DIR, glob='*/state.json'): loader = Loader(d) try: yield from loader.load() @@ -198,14 +186,10 @@ def iter_entries() -> Iterator[Result]: def get_entries() -> List[Result]: # sorting by first annotation is reasonable I guess??? - # TODO return list(sort_res_by(iter_entries(), key=lambda e: e.created)) def main(): - logger = get_logger() - setup_logger(logger, level=logging.DEBUG) - for entry in iter_entries(): logger.info('processed %s', entry.uid) try: @@ -215,7 +199,3 @@ def main(): else: for i in ee.items: logger.info(i) - - -if __name__ == '__main__': - main()