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:
Dima Gerasimov 2022-05-31 19:08:39 +01:00 committed by karlicoss
parent 5799c062a5
commit 2025d7ad1a
10 changed files with 20 additions and 58 deletions

View file

View file

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

View file

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