#! /usr/bin/env python3 # -*- coding: utf-8 -*- """Timewarrior adapter for `argos `.""" # timewarrior # v1.0 # Tobias Schmidl # schtobia # Greps and formats data from timewarrior. # # python,timew # https://gitlab.com/schtobia/argos-timewarrior/blob/master/timewarrior.py import functools import locale from datetime import datetime, timedelta from timew import TimeWarrior # type: ignore __author__ = "Tobias Schmidl" __copyright__ = "Copyright 2021, Tobias Schmidl" __license__ = "MIT" __version__ = "1.0" __maintainer__ = "Tobias Schmidl" TW = TimeWarrior() TIMEFORMATTER = '%Y%m%dT%H%M%S%z' locale.setlocale(locale.LC_ALL, '') RESULTS = sorted(map( lambda x: { 'start': datetime.strptime(x['start'], TIMEFORMATTER).astimezone(tz=None), 'end': datetime.strptime(x['end'], TIMEFORMATTER).astimezone(tz=None) if 'end' in x else datetime.now().astimezone(tz=None), 'id': x['id'], 'tags': x['tags'] if 'tags' in x else None }, TW.summary()), key=lambda x: x['start']) IS_ACTIVE = len(list(filter(lambda x: "end" not in x, TW.summary()))) > 0 TOTAL_TIME = functools.reduce(lambda total, x: total + x['end'] - x['start'], RESULTS, timedelta()) TOTAL_TIME_HOURS, TOTAL_TIME_REMAINDER = divmod(int(TOTAL_TIME.total_seconds()), 3600) TOTAL_TIME_MINUTES, _ = divmod(TOTAL_TIME_REMAINDER, 60) print("⏳" if IS_ACTIVE else "⌛", f"{TOTAL_TIME_HOURS:02}:{TOTAL_TIME_MINUTES:02}", "✓" if not IS_ACTIVE else "") print("---") print( " | font=monospace | size=8\n".join( map( lambda x: str({ 'start': datetime.strftime(x['start'], "%x %X"), 'end': datetime.strftime(x['end'], "%x %X"), 'tags': x['tags'] }), RESULTS)), "| font=monospace | size=8")