-
Notifications
You must be signed in to change notification settings - Fork 0
/
timetrack.py
executable file
·45 lines (36 loc) · 918 Bytes
/
timetrack.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
37
38
39
40
41
42
43
44
#!/usr/bin/python3
import sys
import os
from datetime import datetime, date, time
FILENAME = os.path.expanduser("~/Dropbox") + '/times.txt'
DATEFORMAT = "%Y/%m/%d %H:%M"
DAYSEPERATOR = "\n============================================================\n\n"
TIMETASKSEPARATOR = " | "
now = datetime.now()
newday = False
f_track = open(FILENAME,"r")
lines = f_track.readlines()
f_track.close()
if lines:
lastline = lines[-1]
if lastline.find("|")>=0:
lastdates = lastline[:lastline.find("|")].strip()
lastdate = datetime.strptime(lastdates,DATEFORMAT)
if lastdate.day != now.day:
newday = True
buf = ""
if newday:
buf+=DAYSEPERATOR
buf+=now.strftime(DATEFORMAT)
buf+=TIMETASKSEPARATOR
args = sys.argv[1:]
if len(args) > 1:
if args[0] == "-project":
buf+= "[" + args[1] + "] "
args = args[2:]
buf+=" ".join(args)
buf+="\n"
f_track = open(FILENAME,"a")
f_track.write(buf)
f_track.close()
print(buf)