diff --git a/my/common.py b/my/common.py index ad2eb20..08d2d9f 100644 --- a/my/common.py +++ b/my/common.py @@ -93,3 +93,17 @@ def setup_logger(logger, level=None, format=None, datefmt=None): PathIsh = Union[Path, str] + + +# TODO use glob or something? see in promnesia +def get_files(pp: PathIsh, glob: str) -> List[Path]: + """ + Helper function to avoid boilerplate. + """ + path = Path(pp) + if path.is_dir(): + return list(sorted(path.glob(glob))) + else: + # TODO FIXME assert matches glob?? + raise RuntimeError() + return path diff --git a/foursquare/__init__.py b/my/foursquare.py similarity index 87% rename from foursquare/__init__.py rename to my/foursquare.py index f7a4617..e7b79a7 100755 --- a/foursquare/__init__.py +++ b/my/foursquare.py @@ -1,22 +1,31 @@ #!/usr/bin/env python3 from datetime import datetime, timezone, timedelta -from typing import List, Dict, NamedTuple, Union, Any, Tuple, Set from itertools import chain +from pathlib import Path +from typing import List, Dict, NamedTuple, Union, Any, Tuple, Set import json from pathlib import Path # TODO pytz for timezone??? -from kython import safe_get + # TODO FIXME +from kython import safe_get # type: ignore + +from .common import get_files # TODO actually i'm parsing FSQ in my gmaps thing -_BPATH = Path('/L/backups/4sq') +# TODO eh? def get_logger(): import logging return logging.getLogger("fsq-provider") +def _get_exports() -> List[Path]: + from my_configuration import paths + return get_files(paths.foursquare.export_path, '*.json') + + class Checkin: def __init__(self, j) -> None: self.j = j @@ -53,10 +62,11 @@ class Place: # raise RuntimeError() +# TODO need json type def get_raw(fname=None): if fname is None: - fname = max(_BPATH.glob('*.json')) + fname = max(_get_exports()) j = json.loads(Path(fname).read_text()) assert isinstance(j, list)