-
Notifications
You must be signed in to change notification settings - Fork 0
/
timelog.py
48 lines (38 loc) · 1.39 KB
/
timelog.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
45
46
47
48
# ------------------------------------------------------------------------------
# Python Scripts scriptarium/[timelog.py]
# (c) [email protected]
# ------------------------------------------------------------------------------
import re
def has_timestamp(s):
return re.match(r'^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d.*', s) != None
fname = 'X:\\user\\admin\\timelog.txt'
lines = []
prev = ''
with open(fname, mode='r', encoding='utf-8') as fl:
for ln in fl.read().split('\n'):
if has_timestamp(ln):
# mark times that are the same
# a = ln[:19]
# b = prev[:19]
# if a == b:
# lines.append(ln + ' ``')
# prev = ln
# continue
# mark descriptions that are the same
a = ln[19:]
b = prev[19:]
if a == b:
if prev.find(':00 ') > 0:
lines[len(lines)-1] = '````'
# if prev.find(':00 ') > 0:
# lines[len(lines)-1] = prev + ' ``'
# else:
# lines.append(ln + ' ``')
# prev = ln
# continue
prev = ln
lines.append(ln)
with open(fname, 'wb') as fl:
s = '\n'.join(lines)
fl.write(s.encode('utf8'))
# end