Package: timew-report
timew-reportAn interface forTimewarriorreport data.InstallationUsepipto install the package:pip install timew-reportUsageCreate an executable python script and place it in yourTimewarriorextension folder.Timewarriorwill send its data to the script when called with the extension's name:timew [report] <extension_name>SeeTimewarrior documentationfor more details about this.DetailsThis package consists of three classes which aid processing theTimewarriordata:TimeWarriorParserTimeWarriorConfigTimeWarriorIntervalThe classes are explained in detail below.
You find some usage examples at the bottom of this README.ClassTimeWarriorParserYou can pass an input stream with Timewarrior data to constructor ofTimeWarriorParser:parser = TimeWarriorParser(sys.stdin)Retrieve configuration (asTimeWarriorConfigobject) and intervals (array ofTimeWarriorIntervalobjects):tw_config = parser.get_config()
tw_intervals = parser.get_intervals()ClassTimeWarriorConfigThe objectTimeWarriorConfigencapsulates the configuration dictionary and provides an interface to retrieve values:value = tw_config.get_value(key, default)There is a specialized getter for boolean values which returnsTruefor the givenkeyif the respectivevalueison,1,yes,y, ortrue:bool = tw_config.get_boolean(key, default)There is a specialized getter for integer values:int_val = tw_config.get_int(key, default)In case of a non-parsable string, this function raises aValueErrorexception.There are specialized getters for thedebug,verbose, andconfirmationflag:debug = tw_config.get_debug()
verbose = tw_config.get_verbose()
confirmation = tw_config.get_confirmation()ClassTimeWarriorIntervalTheTimeWarriorIntervalencapsulates the time interval data and provides an interface to retrieve values:start = tw_interval.get_start()
end = tw_interval.get_end()
tags = tw_interval.get_tags()
annotation = tw_interval.get_annotation()startandendaredatetimeobjects and given in local time (endis equal toNoneif the interval is open).tagsis a list of zero or more strings,annotationis a single string orNone.An interval can be queried whether it is open:is_open = tw_interval.is_open()There are methods which return the interval's start or end date (day, month, year) respectively.start_date = tw_interval.get_start_date()
end_date = tw_interval.get_end_date()Note:The functionTimeWarriorInterval.get_date()has been deprecated in favour ofTimeWarriorInterval.get_start_date().ExamplesA simple CSV report:import sys
from timewreport.parser import TimeWarriorParser

parser = TimeWarriorParser(sys.stdin)

for interval in parser.get_intervals():
    line = '"{}"'.format(interval.get_start())
    line += ',"{}"'.format(interval.get_end()) if not interval.is_open() else ''

    for tag in interval.get_tags():
        line += ',"{}"'.format(tag)

    print(line)Summing up totals by tag:import sys
from timewreport.parser import TimeWarriorParser

parser = TimeWarriorParser(sys.stdin)

totals = dict()

for interval in parser.get_intervals():
    tracked = interval.get_duration()

    for tag in interval.get_tags():
        if tag in totals:
            totals[tag] += tracked
        else:
            totals[tag] = tracked

# Determine largest tag width.
max_width = len('Total')

for tag in totals:
    if len(tag) > max_width:
        max_width = len(tag)

# Compose report header.
print('Total by Tag')
print('')

# Compose table header.
print('{:{width}} {:>10}'.format('Tag', 'Total', width=max_width))
print('{} {}'.format('-' * max_width, '----------'))

# Compose table rows.
grand_total = 0
for tag in sorted(totals):
    formatted = totals[tag].seconds
    grand_total += totals[tag].seconds
    print('{:{width}} {:10}'.format(tag, formatted, width=max_width))

# Compose total.
print('{} {}'.format(' ' * max_width, '----------'))
print('{:{width}} {:10}'.format('Total', grand_total, width=max_width))