def progress(): json_data = request.get_json() since = json_data["since"] info = interface.get_progress(since) info = {k : utils.seconds_to_readable_str(v) for k,v in info.items()} resp = jsonify(info=info) return resp
def get_lines(): for week_start, times in weekly_times.items(): times = { topic: seconds_to_readable_str(amount) for topic, amount in times.items() } yield f"{week_start}: {times}"
def splice_tables(title1, title2, it1, it2): it1 = dict_to_table(it1) it1 = map(lambda item: (item[0], seconds_to_readable_str(item[1])), it1) it2 = dict_to_table(it2) it2 = map(lambda item: (item[0], seconds_to_readable_str(item[1])), it2) print('---') print(title1 + titlefont) print(title2 + titlefont + " alternate=true") table1 = tabulate.tabulate(it1, tablefmt="plain") table2 = tabulate.tabulate(it2, tablefmt="plain") lines1 = table1.split('\n') lines2 = table2.split('\n') for l1, l2 in zip_longest(lines1, lines2, fillvalue=""): if l1.strip() == '' and l2.strip() == '': continue print(l1 + tablefont) print(l2 + ' ' + tablefont + ' alternate=true trim=false')
def status(style="text"): """Return a one-line status of what the user is currently doing""" e = read_most_recent() if not e: return "No task history" if e.flag == "ended" or e.flag == "cancelled": seconds = e.time_since_end() subject = "Inactive" else: seconds = e.time_since_start() subject = e.subject if style == "text": return "{}: {}".format(subject, seconds_to_readable_str(seconds, use_days=True)) elif style == "dict": return {'subject': subject, 'time': seconds}
def list_events(days): events = get_progress(datetime.datetime.now() - datetime.timedelta(days=days)) sorted_events = map(lambda a: (a[0], seconds_to_readable_str(a[1])), sorted(events.items(), key=itemgetter(1))) print(tabulate(sorted_events))
def get_total(since): d = get_progress(since) return "Total: {}".format(seconds_to_readable_str(sum(d.values()), 'and'))