Skip to content

Instantly share code, notes, and snippets.

@venik
Last active May 29, 2018 18:29
Show Gist options
  • Save venik/9c34b474241c38f35335b4a69021fb4e to your computer and use it in GitHub Desktop.
Save venik/9c34b474241c38f35335b4a69021fb4e to your computer and use it in GitHub Desktop.
#!/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