use a dict to have keyword access

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2013-04-29 16:38:21 +02:00
parent 7f904fa702
commit dbcecf9970
3 changed files with 20 additions and 16 deletions

View file

@ -75,8 +75,16 @@ Available parameters:
-i, --ignore-case::
ignore case distinctions
-f OUTPUT_FORMAT, --format OUTPUT_FORMAT::
output format (default: {0} ({1}): {2})
output format (default: {start_datetime} ({delta}): {comment})
Output format may reference the following fields:
- start_datetime
- end_datetime
- delta
- delta_seconds
- delta_minutes
- comment
LISTPROJECTS
------------

View file

@ -23,14 +23,14 @@
import os
import os.path
VERSION = "0.8"
VERSION = "0.9"
FILE_DELTA = "delta"
FILE_COMMENT = "comment"
DATEFORMAT = "%Y-%m-%d"
DATEFORMAT_PLAIN= DATEFORMAT.replace("%","")
DATETIMEFORMAT = "%Y-%m-%d-%H%M"
DATETIMEFORMAT_PLAIN= DATETIMEFORMAT.replace("%","")
REPORTFORMAT = "{0} ({1}): {2}"
REPORTFORMAT = "{start_datetime} ({delta}): {comment}"
# Name of the folder to create - should not contain special characters
# to ensure cross-os compatibility

View file

@ -164,22 +164,18 @@ class Report(object):
for time in sorted_times:
entry = self._report_db[time]
report = {}
start_datetime = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT)
delta_seconds = int(float(entry['delta']))
delta_minutes = int(delta_seconds/60)
delta = datetime.timedelta(seconds=int(float(entry['delta'])))
end_datetime = start_datetime + delta
# Strip off microsecends - this is really too much
end_datetime = end_datetime.replace(microsecond = 0)
report['start_datetime'] = datetime.datetime.strptime(time, ctt.DATETIMEFORMAT)
report['delta_seconds'] = int(float(entry['delta']))
report['delta_minutes'] = int(report['delta_seconds']/60)
report['delta'] = datetime.timedelta(seconds=int(float(entry['delta'])))
report['end_datetime'] = (report['start_datetime'] + report['delta']).replace(microsecond = 0)
if 'comment' in entry:
comment = entry['comment']
report['comment'] = entry['comment']
else:
comment = False
report['comment'] = False
print(self.output_format.format(start_datetime, delta, comment, delta_seconds, delta_minutes))
print(self.output_format.format_map(report))