diff --git a/my/arbtt.py b/my/arbtt.py index e672e5b..02e06db 100644 --- a/my/arbtt.py +++ b/my/arbtt.py @@ -3,6 +3,7 @@ ''' REQUIRES = ['ijson', 'cffi'] +# NOTE likely also needs libyajl2 from apt or elsewhere? from pathlib import Path diff --git a/my/coding/__init__.py b/my/coding/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/my/coding/codeforces.py b/my/coding/codeforces.py index 1ac6ba4..3793988 100644 --- a/my/coding/codeforces.py +++ b/my/coding/codeforces.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from my.config import codeforces as config -from datetime import datetime +from datetime import datetime, timezone from typing import NamedTuple import json from typing import Dict, Iterator @@ -10,10 +10,6 @@ from ..core import get_files, Res, unwrap from ..core.compat import cached_property from ..core.konsume import ignore, wrap -from kython import fget -# TODO remove -from kython.kdatetime import as_utc - Cid = int @@ -25,7 +21,7 @@ class Contest(NamedTuple): def make(cls, j) -> 'Contest': return cls( cid=j['id'], - when=as_utc(j['startTimeSeconds']), + when=datetime.fromtimestamp(j['startTimeSeconds'], tz=timezone.utc), ) Cmap = Dict[Cid, Contest] @@ -91,23 +87,4 @@ def iter_data() -> Iterator[Res[Competition]]: def get_data(): - return list(sorted(iter_data(), key=fget(Competition.when))) - - -def test(): - assert len(get_data()) > 10 - - -def main(): - for d in iter_data(): - try: - d = unwrap(d) - except Exception as e: - print(f'ERROR! {d}') - else: - print(f'{d.when}: {d.summary}') - - - -if __name__ == '__main__': - main() + return list(sorted(iter_data(), key=Competition.when.fget)) diff --git a/my/coding/topcoder.py b/my/coding/topcoder.py index 2577dd1..5711254 100644 --- a/my/coding/topcoder.py +++ b/my/coding/topcoder.py @@ -6,18 +6,14 @@ from typing import NamedTuple import json from typing import Dict, Iterator -from ..core import get_files, Res, unwrap +from ..core import get_files, Res, unwrap, Json from ..core.compat import cached_property from ..core.error import Res, unwrap - -# TODO get rid of fget? -from kython import fget from ..core.konsume import zoom, wrap, ignore -# TODO json type?? -def _get_latest() -> Dict: - pp = max(get_files(config.export_path, glob='*.json')) +def _get_latest() -> Json: + pp = max(get_files(config.export_path)) return json.loads(pp.read_text()) @@ -82,21 +78,5 @@ def iter_data() -> Iterator[Res[Competition]]: def get_data(): - return list(sorted(iter_data(), key=fget(Competition.when))) + return list(sorted(iter_data(), key=Competition.when.fget)) - -def test(): - assert len(get_data()) > 10 - -def main(): - for d in iter_data(): - try: - d = unwrap(d) - except Exception as e: - print(f'ERROR! {d}') - else: - print(d.summary) - - -if __name__ == '__main__': - main() diff --git a/my/fbmessenger/__init__.py b/my/fbmessenger/__init__.py index 910d7a6..2e60d17 100644 --- a/my/fbmessenger/__init__.py +++ b/my/fbmessenger/__init__.py @@ -53,3 +53,7 @@ if legacy: REQUIRES = [ 'git+https://github.com/karlicoss/fbmessengerexport', ] + + +# to prevent it from apprearing in modules list/doctor +from ..core import __NOT_HPI_MODULE__ diff --git a/my/foursquare.py b/my/foursquare.py index 7325f3c..b50ab0e 100755 --- a/my/foursquare.py +++ b/my/foursquare.py @@ -17,7 +17,7 @@ logger = LazyLogger(__name__) def inputs(): - return get_files(config.export_path, '*.json') + return get_files(config.export_path) class Checkin: @@ -61,7 +61,7 @@ class Place: def get_raw(fname=None): if fname is None: fname = max(inputs()) - j = json.loads(Path(fname).read_text()) + j = json.loads(fname.read_text()) assert isinstance(j, list) for chunk in j: diff --git a/my/jawbone/__init__.py b/my/jawbone/__init__.py index 06cb262..28ef937 100755 --- a/my/jawbone/__init__.py +++ b/my/jawbone/__init__.py @@ -110,7 +110,7 @@ def pre_dataframe() -> Iterable[Res[SleepEntry]]: sleeps = load_sleeps() # todo emit error if graph doesn't exist?? sleeps = [s for s in sleeps if s.graph.exists()] # TODO careful.. - from ..common import group_by_key + from ..core.common import group_by_key for dd, group in group_by_key(sleeps, key=lambda s: s.date_).items(): if len(group) == 1: yield group[0] diff --git a/my/media/imdb.py b/my/media/imdb.py index c7d5299..63531fe 100644 --- a/my/media/imdb.py +++ b/my/media/imdb.py @@ -3,12 +3,12 @@ import csv from datetime import datetime from typing import Iterator, List, NamedTuple -from ..common import get_files +from ..core import get_files from my.config import imdb as config def _get_last(): - return max(get_files(config.export_path, glob='*.csv')) + return max(get_files(config.export_path)) class Movie(NamedTuple): diff --git a/my/roamresearch.py b/my/roamresearch.py index 20a4391..0c1192f 100644 --- a/my/roamresearch.py +++ b/my/roamresearch.py @@ -17,7 +17,7 @@ logger = LazyLogger(__name__) def last() -> Path: - return max(get_files(config.export_path, '*.json')) + return max(get_files(config.export_path)) class Keys: diff --git a/tests/core.py b/tests/core.py index 72c16ef..339f786 100644 --- a/tests/core.py +++ b/tests/core.py @@ -3,9 +3,9 @@ NOTE: Sigh. it's nice to be able to define the tests next to the source code (so However, if you run 'pytest --pyargs my.core', it detects 'core' package name (because there is no my/__init__.py) (see https://docs.pytest.org/en/latest/goodpractices.html#tests-as-part-of-application-code) -This results in relative imports failing (e.g. from ..kython import...). +This results in relative imports failing (e.g. from ..core import...). -By using this helper file, pytest can detect the package name properly. A bit meh, but perhaps after kython is moved into the core, +By using this helper file, pytest can detect the package name properly. A bit meh, but perhaps later, we can run against the tests in my.core directly. '''