f33aa9ae43
This change adds new report, update_days, that nicely displays how many days ago a package was updated. This report is now available in interactive mode and included into daily report.
47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
|
|
import datetime
|
|
import json
|
|
import time
|
|
|
|
|
|
def format_timestamp(ts, fmt='%Y-%m-%d %H:%M:%S'):
|
|
dt = datetime.datetime.fromtimestamp(ts)
|
|
return dt.strftime(fmt)
|
|
|
|
|
|
_EPOCH = datetime.datetime.utcfromtimestamp(0)
|
|
|
|
|
|
def to_timestamp(dt):
|
|
return (dt - _EPOCH).total_seconds()
|
|
|
|
|
|
def maybe_int(value):
|
|
try:
|
|
return int(value)
|
|
except ValueError:
|
|
return value
|
|
|
|
|
|
def days_from(ts, now=None):
|
|
now = now or time.time()
|
|
return int((now - ts) / 24 / 60 / 60)
|
|
|
|
|
|
def _transform_to_format(value):
|
|
if isinstance(value, dict):
|
|
return dict((maybe_int(k), _transform_to_format(v))
|
|
for k, v in value.iteritems())
|
|
if isinstance(value, (list, tuple)):
|
|
return [_transform_to_format(v) for v in value]
|
|
return value
|
|
|
|
|
|
def format_dict(data, indent=False):
|
|
out = _transform_to_format(data)
|
|
if indent:
|
|
return json.dumps(out, sort_keys=True,
|
|
indent=2, separators=(',', ': '))
|
|
else:
|
|
return json.dumps(out, sort_keys=True)
|