#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
from time import time
time_stamp = time()
__author__ = 'Anton Vlasenko'
pattern = re.compile(r'(\d+).*?<\/a>')
num_replacing_pattern = re.compile(r'(\d+).*?<\/a>')
# To make this work: put search results generated by twisted-based server into two
# separate files - 1.txt and 2.txt in the current folder.
# This program will compare results and if the difference is more\less than 25% - it
# will colourize the cell.
with open('1.txt', 'r') as f1, open('2.txt', 'r') as f2:
f1 = f1.readlines()
f2 = f2.readlines()
for line in f1:
match1 = pattern.search(line)
if match1:
number1 = match1.group(2)
#print 'Group2 first match:', number1
for line_number, line_ in enumerate(f2):
# maybe this looks somekind weird and not optimized, but it works anyway
match2 = pattern.search(line_)
if not match2:
continue
#print (match2.group(4))
if int(match2.group(4)) < 1000:
continue
if match2.group(1) == match1.group(1):
if int(match2.group(4)) > int(match1.group(4))+int(match2.group(4))*.25:
f2[line_number] = line_.replace(match2.group(4), '%s
' % match2.group(4))
#f2[line_number] = line_ + '\n'
elif int(match1.group(4)) > int(match2.group(4))+int(match2.group(4))*.25:
f2[line_number] = line_.replace(match2.group(4), '%s
' % match2.group(4))
#f2[line_number] = line_ + '\n'
pass
break
print ('test2')
with open('result.txt', 'w') as f_out:
f_out.write(''.join(f1+f2))
print ('Time of execution: ' + str(time()-time_stamp))
print ('FIN')