Use configuration in foursquare module

This commit is contained in:
Dima Gerasimov 2019-11-27 12:01:29 +00:00
parent e11adb3a09
commit 661218ebe9
2 changed files with 28 additions and 4 deletions

View file

@ -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

View file

@ -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)