-
Notifications
You must be signed in to change notification settings - Fork 0
/
pytimer.py
36 lines (30 loc) · 1.09 KB
/
pytimer.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
import csv
import time
from datetime import datetime
def start_task(task_name):
start_time = time.time()
return task_name, start_time
def end_task(task_name, start_time):
end_time = time.time()
elapsed_time = end_time - start_time
log_time(task_name, elapsed_time)
def log_time(task_name, elapsed_time):
date_str = datetime.now().strftime("%Y-%m-%d|%H:%M:%S")
hours, remainder = divmod(elapsed_time, 3600)
minutes, seconds = divmod(remainder, 60)
time_spent = f"{int(hours)}h {int(minutes)}m {int(seconds)}s"
with open('/Users/zzigak/timer/pytimer_times.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([date_str, task_name, time_spent])
def main(task_name):
print(f"Starting task: {task_name}")
task_name, start_time = start_task(task_name)
input("Press Enter to stop the task...")
end_task(task_name, start_time)
print(f"Task '{task_name}' logged.")
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print("Usage: pytimer.py taskName")
else:
main(sys.argv[1])