Created
March 15, 2016 02:17
-
-
Save ernestom/6a87b1006c8b3fd42729 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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