Skip to content

Instantly share code, notes, and snippets.

@fredkingham
Last active October 24, 2017 10:37
Show Gist options
  • Save fredkingham/6ae20a15e8bbbae330c3b58746502a10 to your computer and use it in GitHub Desktop.
Save fredkingham/6ae20a15e8bbbae330c3b58746502a10 to your computer and use it in GitHub Desktop.
import datetime
import json
def read_date(line):
dt = line[line.index('[') + 1: line.index(']')]
dt = dt.split(" ")[0]
return datetime.strptime(dt, '%d/%b/%Y:%H:%M:%S')
def read_json(line):
json_obj = line[line.index('{'):(line.rfind('}')+1)]
json_obj = json_obj.decode('string_escape')
return json.loads(json_obj)
def read_file(some_file_name):
result = {}
with open(some_file_name) as f:
txt = f.read().split('\n')
for i in txt:
if 'POST' in i:
result[read_date(i)] = read_json(i)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment