cli: integrate with stats reported by the modules
This commit is contained in:
parent
d890599c7c
commit
7bd7cc9228
7 changed files with 49 additions and 4 deletions
|
@ -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
|
||||
|
||||
else:
|
||||
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' - stats: {res}')
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def list_modules(args):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()),
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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])
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
2
tox.ini
2
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]
|
||||
|
|
Loading…
Add table
Reference in a new issue