Completed
Push — master ( b84d89...87aa7c )
by Andrew
01:16
created

get_order()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
import datetime
2
import re
3
from sys import argv
4
5
6
def get_order(f):
7
	line = f.readline()
8
	res = re.match(r"\w+:\w+\s\[(\d\d:\d\d:\d\d:\d\d\d);", line)
9
	d = datetime.datetime.strptime(res.group(1), '%H:%M:%S:%f') if res else None
10
	return line, d
11
12
f1 = open(argv[1] if len(argv) >= 2 else './tornado-8881.log')
13
f2 = open(argv[2] if len(argv) >= 3 else './tornado-8882.log')
14
f3 = open(argv[3] if len(argv) >= 3 else './tornado.log', 'w')
15
16
l1, d1 = get_order(f1)
17
l2, d2 = get_order(f2)
18
19
while True:
20
	if not l1 and not l2:
21
		break
22
	if l1 and ((not d1 and d2) or (d2 and d1 < d2)):
23
		f3.write(l1)
24
		l1, d1 = get_order(f1)
25
	elif l2:
26
		f3.write(l2)
27
		l2, d2 = get_order(f2)
28