Skip to content

Instantly share code, notes, and snippets.

@norbinsh
Created September 27, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save norbinsh/734c0892934780b3e0c12c727c9b1e30 to your computer and use it in GitHub Desktop.
Save norbinsh/734c0892934780b3e0c12c727c9b1e30 to your computer and use it in GitHub Desktop.
import re
import json
regex_pattern = r"^logzero_default - (\d{4}-\d\d-\d\d).*INFO: ([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+), \d*. (.*).zip$"
input_file = 'logfile.log'
def return_rows(input_file):
with open(input_file, 'r') as inputf:
return inputf.read().splitlines()
data_list = [re.split(regex_pattern, row) for row in return_rows(input_file)]
versions_set = list(set(version[3] for version in data_list))
data_dict = {ver: {date: list() for date in (set(date[1] for date in data_list))} for ver in versions_set}
for row in data_list:
data_dict[row[3]][row[1]].append(row[2])
with open("data.json", "w") as json_file:
json.dump(data_dict, json_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment