Skip to content

Instantly share code, notes, and snippets.

@ernestom
Created March 15, 2016 02:17
Show Gist options
  • Save ernestom/6a87b1006c8b3fd42729 to your computer and use it in GitHub Desktop.
Save ernestom/6a87b1006c8b3fd42729 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import re
from datetime import datetime
def parse(line):
parser = re.compile(
r'API VALIDATION: (?P<valid>[01]{1}) \| '
r'tokensMatch: (?P<tokensMatch>[01]{1}) \| '
r'uniqueToken: (?P<uniqueToken>[01]{1}) \| '
r'validRequestTimestamp: (?P<validRequestTimestamp>[01]{1}) \|\| '
r'minTime: (?P<minTime>\d+) '
r'serverTime: (?P<serverTime>\d+) '
r'maxTime: (?P<maxTime>\d+) '
r'requestTime: (?P<requestTime>\d+) \|\| '
r'IP: (?P<ip>[\d.]+)'
)
groups = parser.search(line).groups()
tokensMatch, uniqueToken, validRequestTimestamp = [g == "1" for g in groups[1:4]]
minTime, serverTime, maxTime, requestTime = [int(g) for g in groups[4:8]]
ip = groups[-1]
print ip,
if not validRequestTimestamp:
diff = serverTime - requestTime
user_date = datetime.fromtimestamp(requestTime).strftime('%Y-%m-%d %H:%M:%S')
message = (
'TIMESTAMP ' + ('ATRASADO' if diff > 0 else 'ADELANTADO'),
str((abs(diff)) / 60 / 60),
user_date
)
print ','.join(message)
if not uniqueToken:
print 'TOKEN DUPLICADO'
if __name__ == '__main__':
for line in sys.stdin:
parse(line.strip())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment