Last active
December 26, 2015 12:59
-
-
Save t0mmyt/7154865 to your computer and use it in GitHub Desktop.
Populate dict from bzipped log file
This file contains hidden or 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
def populate(file, result): | |
''' | |
Read bzipped syslog and match re below, append to dict referred to | |
by result. | |
Requires re and bz2 | |
''' | |
f = BZ2File(file, 'r') | |
re_aide = re.compile('^\w+ \d+ \d\d:\d\d:\d\d ([\w\-\.]+) aide: (.*)$') | |
while 1: | |
lines = f.readlines(8192) | |
if not lines: | |
break | |
for line in lines: | |
m = re_aide.match(line) | |
if m: | |
s, d = m.group(1), m.group(2) | |
if s not in result or not isinstance(result[s], list): | |
result[m.group(1)] = [] | |
result[s].append(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment