-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworking.py
More file actions
executable file
·48 lines (41 loc) · 1000 Bytes
/
working.py
File metadata and controls
executable file
·48 lines (41 loc) · 1000 Bytes
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
45
46
47
48
#!/usr/bin/env python3
import os
import sys
import datetime
FILE_EXT = 'Wissen' + os.sep + 'working.txt'
DB = os.getenv('HOME', 'c:/tmp')
FILE = DB + os.sep + FILE_EXT
def calc():
dict = read_data()
keys = list(dict.keys())
keys.sort()
for k in keys:
print("%s %3.1d" % (k, dict.get(k)))
# for k, v in dict.iteritems():
# print k, v
def read_data():
d = {}
for i in open(FILE):
if i.find('#') == 0:
continue
date, value = i.strip().split()
v = int(value)
#print("XXX: ", date,'->', v)
if date in d:
d[date] = d[date] + v
else:
d[date] = v
print('Now: ', date, '->', d[date])
return d
def main():
arg = 0
d = datetime.date.today()
if len(sys.argv) > 1:
arg = sys.argv[1]
if arg > 0:
out = open(FILE, 'a')
out.write("%s %s\n" % (d, arg))
else:
calc()
if __name__ == '__main__':
main()