diff --git a/my/core/__main__.py b/my/core/__main__.py index 2de9537..c80bae3 100644 --- a/my/core/__main__.py +++ b/my/core/__main__.py @@ -100,20 +100,34 @@ def config_check(args): def modules_check(args): verbose = args.verbose + vw = '' if verbose else '; pass --verbose to print more information' from .util import get_modules for m in get_modules(): try: - importlib.import_module(m) + mod = importlib.import_module(m) except Exception as e: # todo more specific command? - vw = '' if verbose else '; pass --verbose to print more information' warning(f'{color.RED}FAIL{color.RESET}: {m:<30} loading failed{vw}') if verbose: tb(e) + continue + info(f'{color.GREEN}OK{color.RESET} : {m:<30}') + stats = getattr(mod, 'stats', None) + if stats is None: + continue + try: + res = stats() + except Exception as ee: + warning(f' - {color.RED}stats:{color.RESET} computing failed{vw}') + if verbose: + tb(ee) else: - info(f'{color.GREEN}OK{color.RESET} : {m:<30}') + info(f' - stats: {res}') + + + def list_modules(args): diff --git a/my/emfit/__init__.py b/my/emfit/__init__.py index 2b8f5a8..93ea337 100755 --- a/my/emfit/__init__.py +++ b/my/emfit/__init__.py @@ -322,6 +322,12 @@ def by_night() -> Dict[date, Emfit]: return res +def stats(): + return { + 'nights': len(by_night()), + } + + def main(): for k, v in by_night().items(): print(k, v.start, v.end) diff --git a/my/foursquare.py b/my/foursquare.py index ed55a24..a722b3a 100755 --- a/my/foursquare.py +++ b/my/foursquare.py @@ -90,3 +90,10 @@ def get_cid_map(bfile: str): def print_checkins(): print(get_checkins()) + + +def stats(): + from more_itertools import ilen + return { + 'checkins': ilen(get_checkins()), + } diff --git a/my/hypothesis.py b/my/hypothesis.py index bacc51e..d3d95c2 100644 --- a/my/hypothesis.py +++ b/my/hypothesis.py @@ -69,6 +69,16 @@ def pages() -> List[Res[Page]]: return sort_res_by(_dal().pages(), key=lambda h: h.created) +# todo not public api yet +def stats(): + # todo add 'last date' checks et + return { + # todo ilen + 'highlights': len(highlights()), + 'pages' : len(pages()), + } + + def _main(): for page in get_pages(): print(page) diff --git a/my/rss/feedbin.py b/my/rss/feedbin.py index 5a2f117..4cd1b8d 100644 --- a/my/rss/feedbin.py +++ b/my/rss/feedbin.py @@ -40,3 +40,10 @@ def states() -> Iterable[SubscriptionState]: dt = isoparse(dts) subs = parse_file(f) yield dt, subs + + +def stats(): + from more_itertools import ilen, last + return { + 'subscriptions': ilen(last(states())[1]) + } diff --git a/tests/foursquare.py b/tests/foursquare.py index 040f56c..ae9612e 100644 --- a/tests/foursquare.py +++ b/tests/foursquare.py @@ -1,6 +1,7 @@ from my.foursquare import get_checkins def test_checkins(): + # todo reuse stats? checkins = get_checkins() assert len(checkins) > 100 assert any('Victoria Park' in c.summary for c in checkins) diff --git a/tox.ini b/tox.ini index ba5ac70..9a724a3 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ commands = # TODO add; once I figure out porg depdencency?? tests/config.py # TODO run demo.py? just make sure with_my is a bit cleverer? # TODO e.g. under CI, rely on installing - hpi hello + hpi modules [testenv:demo]