Last active
January 1, 2016 02:49
-
-
Save DanielOaks/8081544 to your computer and use it in GitHub Desktop.
unifies znc logs
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 python3 | |
# ZNC log unifier | |
# assumes all the logs are in folder 'log' | |
# and all files are output to folder 'outlog' | |
# This basically changes all the logs like: | |
# log/danneh_rizon_#chan_20142304.log | |
# log/danneh_rizon_#chan_20142305.log | |
# log/danneh_rizon_#chan_20142306.log | |
# to: | |
# outlog/danneh_rizon_#chan.log | |
# | |
# And makes every line in the new log have the date, from this: | |
# [19:32:05] <Dandan> jjjjjjjjjjjjjjj | |
# to: | |
# [2014-23-04][19:32:05] <Dandan> jjjjjjjjjjjjjjj | |
import os | |
import re | |
if not os.path.exists('outlog'): | |
os.makedirs('outlog') | |
p = re.compile('([a-z]+)_([^_]+)_([\S]+)_([0-9]+)\.log') | |
for log in os.listdir('log'): | |
# try: | |
user = p.match(log).group(1) | |
network = p.match(log).group(2) | |
target = p.match(log).group(3) | |
date = p.match(log).group(4) | |
outpath = 'outlog/{}_{}_{}.log'.format(user, network, target) | |
outline = '[{}-{}-{}]{{}}'.format(date[0:4], date[4:6], date[6:8]) | |
if not os.path.exists(outpath): | |
open(outpath, 'w').close() | |
with open(outpath, 'a', encoding='utf-8', errors='ignore') as outfile: | |
with open('log/{}'.format(log), encoding='utf-8', errors='ignore') as infile: | |
for line in infile: | |
outfile.write(outline.format(line)) | |
# except: | |
# print('FAILED:', log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment