Add option to pass a different file

time.txt in the current directory is the default, but another path can be passed too.
This commit is contained in:
karl 2020-12-15 00:14:00 +01:00
parent abf61299a0
commit 59722e19a2

13
tx
View File

@ -1,8 +1,21 @@
#!/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")
args = parser.parse_args()
if args.file:
time_file = open(args.file,'r')
else:
time_file = open('time.txt','r')
total_time = timedelta()
for line in time_file: