An interface for Timewarrior report data
Project description
timew-report
An interface for Timewarrior report data.
Installation
Use pip to install the package:
pip install timew-report
Usage
Create an executable python script and place it in your Timewarrior extension folder.
Timewarrior will send its data to the script when called with the extension's name:
timew [report] <extension_name>
See Timewarrior documentation for more details about this.
Details
This package consists of three classes which aid processing the Timewarrior data:
TimeWarriorParserTimeWarriorConfigTimeWarriorInterval
The classes are explained in detail below. You find some usage examples at the bottom of this README.
Class TimeWarriorParser
You can pass an input stream with Timewarrior data to constructor of TimeWarriorParser:
parser = TimeWarriorParser(sys.stdin)
Retrieve configuration (as TimeWarriorConfig object) and intervals (array of TimeWarriorInterval objects):
tw_config = parser.get_config()
tw_intervals = parser.get_intervals()
Class TimeWarriorConfig
The object TimeWarriorConfig encapsulates 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 returns True for the given key if the respective value is on, 1, yes, y, or true:
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 a ValueError exception.
There are specialized getters for the debug, verbose, and confirmation flag:
debug = tw_config.get_debug()
verbose = tw_config.get_verbose()
confirmation = tw_config.get_confirmation()
Class TimeWarriorInterval
The TimeWarriorInterval encapsulates 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()
start and end are datetime objects and given in local time (end is equal to None if the interval is open).
tags is a list of zero or more strings, annotation is a single string or None.
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 function TimeWarriorInterval.get_date() has been deprecated in favour of TimeWarriorInterval.get_start_date().
Examples
A 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))
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file timew-report-1.4.0.tar.gz.
File metadata
- Download URL: timew-report-1.4.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
439ec4dda62215ff347971095d99566678be3c9e3c5dbecdb8bed51fd4422f90
|
|
| MD5 |
f3c2f2168fc240077d31502d880645eb
|
|
| BLAKE2b-256 |
384e3f47c29a5fdd29ef33ae717409f6109671ee3cd276233635b541b14f3588
|
File details
Details for the file timew_report-1.4.0-py3-none-any.whl.
File metadata
- Download URL: timew_report-1.4.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b50cbda98ebc146cd3bb39312ad8c5c0fe066d8785952dd85623a4032c5c9b75
|
|
| MD5 |
0c840862e2839d4afb801fd5f5c50552
|
|
| BLAKE2b-256 |
e69fbcbe492419ab7ef584bfe8d154b19630ed9989181116c2f533e063cf6e49
|