From 59722e19a2ca5c951507f8ef4c22c4062270fc10 Mon Sep 17 00:00:00 2001 From: karl Date: Tue, 15 Dec 2020 00:14:00 +0100 Subject: [PATCH] Add option to pass a different file time.txt in the current directory is the default, but another path can be passed too. --- tx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tx b/tx index f95a2d5..b1c8032 100755 --- a/tx +++ b/tx @@ -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') -time_file = open('time.txt','r') total_time = timedelta() for line in time_file: