add configure method to instapaper module

This commit is contained in:
Dima Gerasimov 2019-11-07 19:18:54 +00:00
parent 12b7aa919e
commit fdf1a3f935
4 changed files with 24 additions and 6 deletions

View file

@ -89,7 +89,7 @@ with_my orger/modules/polar.py --to polar.org
#+begin_src bash #+begin_src bash
# see https://github.com/python/mypy/issues/1645 for --namespace-packages explanation # see https://github.com/python/mypy/issues/1645 for --namespace-packages explanation
with_my --namespace-packages my with_my mypy --namespace-packages my
#+end_src #+end_src
or, set up as ~mypy.ini~ file: or, set up as ~mypy.ini~ file:

View file

@ -10,3 +10,4 @@ try:
except ImportError: except ImportError:
import warnings import warnings
warnings.warn("my_configuration package isn't found! That might result in issues") warnings.warn("my_configuration package isn't found! That might result in issues")
paths = None # type: ignore

View file

@ -90,3 +90,6 @@ def setup_logger(logger, level=None, format=None, datefmt=None):
) )
finally: finally:
logging.root = old_root logging.root = old_root
PathIsh = Union[Path, str]

View file

@ -6,11 +6,25 @@ from collections import OrderedDict
import pytz import pytz
from . import paths from .common import group_by_key, PathIsh
from .common import group_by_key
def get_files():
return list(sorted(Path(paths.instapexport.export_dir).glob('*.json'))) _export_dir: Optional[Path] = None
def configure(*, export_dir: Optional[PathIsh]=None) -> None:
if export_dir is not None:
global _export_dir
_export_dir = Path(export_dir)
def _get_files():
export_dir = _export_dir
if export_dir is None:
# fallback to my_configuration
from . import paths
export_dir = paths.instapexport.export_dir
return list(sorted(Path(export_dir).glob('*.json')))
Bid = str Bid = str
@ -60,7 +74,7 @@ def get_stuff(limit=0) -> Tuple[BDict, HDict]:
all_bks: BDict = OrderedDict() all_bks: BDict = OrderedDict()
all_hls: HDict = OrderedDict() all_hls: HDict = OrderedDict()
# TODO can restore url by bookmark id # TODO can restore url by bookmark id
for f in get_files()[-limit:]: for f in _get_files()[-limit:]:
with f.open('r') as fo: with f.open('r') as fo:
j = json.load(fo) j = json.load(fo)
for b in sorted(j['bookmarks'], key=dkey('time')): for b in sorted(j['bookmarks'], key=dkey('time')):