Compare commits

...

3 Commits

Author SHA1 Message Date
20a66b8f48 Add mode argument, default 'total' 2020-12-15 00:34:52 +01:00
59722e19a2 Add option to pass a different file
time.txt in the current directory is the default, but another path can be passed too.
2020-12-15 00:14:00 +01:00
abf61299a0 Add basic code and example 2020-12-14 23:50:16 +01:00
2 changed files with 38 additions and 0 deletions

4
time.txt Normal file
View File

@ -0,0 +1,4 @@
2020-08-12 01:00 Work on Task 1
2020-08-12 03:00 Work on Task 2
2020-08-16 05:00 Finish Task 2
2020-08-31 -08:00 Fee note for August

34
tx Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
from datetime import datetime, timedelta
import argparse
# Parse command line arguments
parser = argparse.ArgumentParser(description="Description")
# add arguments to the parser
parser.add_argument("-f", "--file")
parser.add_argument("mode",
help="display the square of a given number",
nargs='?', default="total",
choices=["total"])
args = parser.parse_args()
if args.file:
time_file = open(args.file,'r')
else:
time_file = open('time.txt','r')
if args.mode == "total":
total_time = timedelta()
for line in time_file:
date_time_description = line.split(" ", 2)
hours, minutes = date_time_description[1].split(':', 1)
delta = timedelta(hours=int(hours), minutes=int(minutes))
total_time += delta
print('Total time: ', total_time)