-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrep_tl.py
executable file
·61 lines (47 loc) · 1.89 KB
/
rep_tl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
import argparse
import datetime
import os
from gtimelog.timelog import TimeLog, format_duration_short
virtual_midnight = datetime.time(2, 0)
def set_logfile(argfile=None):
if argfile is not None:
return argfile[0]
else:
env = os.environ.get("GTIMELOG_FILE")
if env is not None:
return env
return '%s/.local/share/gtimelog/timelog.txt' % os.path.expanduser("~")
def get_time():
today = datetime.datetime.today()
today = today.replace(hour=0, minute=0, second=0, microsecond=0)
week_first = today - datetime.timedelta(days=today.weekday())
week_last = week_first + datetime.timedelta(days=6)
week_last = week_last.replace(hour=23, minute=59, second=59)
return (week_first, week_last)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--logfile', nargs=1, metavar='LOGFILE',
help='Path to the gtimelog logfile to be use')
args = parser.parse_args()
if args.logfile is not None:
LogFile = set_logfile(args.logfile)
else:
LogFile = set_logfile()
(week_first, week_last) = get_time()
Log = TimeLog(LogFile, virtual_midnight)
log_entries = Log.window_for(week_first, week_last)
total_work, _ = log_entries.totals()
_, totals = log_entries.categorized_work_entries()
ordered_by_time = [(time, cat) for cat, time in totals.items()]
ordered_by_time.sort(reverse=True)
max_cat_length = max([len(cat) for cat in totals.keys()])
line_format = ' %-' + str(max_cat_length + 4) + 's %+5s\t %.0f%%'
print("\nTotal work done so far : %s\n" %
format_duration_short(total_work))
print('Categories by time spent:')
for time, cat in ordered_by_time:
print(line_format % (cat, format_duration_short(time),
time / total_work * 100))
if __name__ == '__main__':
main()