Skip to content

Instantly share code, notes, and snippets.

@venik venik/ForAlex.py
Last active May 29, 2018

Embed
What would you like to do?
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import sys
import time
from datetime import datetime
keyString = u'купить'
goodString = u'купюра'
timeThreshold = 90 # seconds timescale
def main():
if (len(sys.argv) < 2):
print('Usage: ./script log.name')
return -1
with open(sys.argv[1], 'r') as f:
content = f.readlines()
blockNum = 0
lastDt = sys.maxint
for lineString in reversed(content):
strBlock = lineString.split(' ')
# skip lines with less than 3 tokens
if (len(strBlock) < 3):
continue
if (strBlock[-3].decode('utf-8') == goodString):
break
if (strBlock[-2].decode('utf-8') == keyString):
dateStr = strBlock[0] + ' ' + strBlock[1]
dt = int(time.mktime(datetime.strptime(dateStr, '%d.%m.%Y %H:%M:%S.%f').timetuple()))
print(str(lineString))
if lastDt != sys.maxint and (lastDt - dt) > timeThreshold:
blockNum = blockNum + 1
lastDt = dt
#print(str(lastDt))
print(str(blockNum))
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.