-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubtract_lines.py
More file actions
executable file
·38 lines (26 loc) · 861 Bytes
/
subtract_lines.py
File metadata and controls
executable file
·38 lines (26 loc) · 861 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
#!/usr/bin/env python
import re
import sys
import datetime
import math
first_line = None
last_line = None
for line in sys.stdin:
if last_line:
print(last_line, end="")
if not first_line:
first_line = line
last_line = line
date_re = re.compile(r'^[0-9-_]+')
first_date_match = date_re.match(first_line)
last_date_match = date_re.match(last_line)
if first_date_match and last_date_match:
first_date = first_date_match.group()
last_date = last_date_match.group()
first_time = datetime.datetime.strptime(first_date, "%Y-%m-%d_%H-%M-%S")
last_time = datetime.datetime.strptime(last_date, "%Y-%m-%d_%H-%M-%S")
dt_time = last_time - first_time
numsec = int(dt_time.total_seconds())
nummin = int(math.ceil( (numsec + 10.0) / 60.0))
print("\nrest {} min\n".format(nummin))
print(last_line, end="")