general: minor cleanup
- get rid of unnecessary globs in get_files (they should be in config if the user wishes) - get rid of some old kython imports - do not convert Path twice in foursquare (so CPath works correctly)
This commit is contained in:
parent
5799c062a5
commit
2025d7ad1a
10 changed files with 20 additions and 58 deletions
|
@ -3,6 +3,7 @@
|
|||
'''
|
||||
|
||||
REQUIRES = ['ijson', 'cffi']
|
||||
# NOTE likely also needs libyajl2 from apt or elsewhere?
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue