Add prototype 'add' mode
This commit is contained in:
parent
20a66b8f48
commit
f4a2735da0
12
tx
12
tx
@ -11,16 +11,14 @@ parser.add_argument("-f", "--file")
|
|||||||
parser.add_argument("mode",
|
parser.add_argument("mode",
|
||||||
help="display the square of a given number",
|
help="display the square of a given number",
|
||||||
nargs='?', default="total",
|
nargs='?', default="total",
|
||||||
choices=["total"])
|
choices=["total", "add"])
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.file:
|
filename = args.file if args.file else 'time.txt'
|
||||||
time_file = open(args.file,'r')
|
|
||||||
else:
|
|
||||||
time_file = open('time.txt','r')
|
|
||||||
|
|
||||||
if args.mode == "total":
|
if args.mode == "total":
|
||||||
|
with open(filename, 'r') as time_file:
|
||||||
total_time = timedelta()
|
total_time = timedelta()
|
||||||
|
|
||||||
for line in time_file:
|
for line in time_file:
|
||||||
@ -32,3 +30,7 @@ if args.mode == "total":
|
|||||||
total_time += delta
|
total_time += delta
|
||||||
|
|
||||||
print('Total time: ', total_time)
|
print('Total time: ', total_time)
|
||||||
|
|
||||||
|
elif args.mode == "add":
|
||||||
|
with open(filename, 'a') as time_file:
|
||||||
|
time_file.write("A new line")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user