encoding utf-8 Talisman bot log parser usage python parser py director

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -*- encoding: utf-8 -*-
# Talisman bot log parser.
# usage: python parser.py directory_name
import os
import re
if __name__ == '__main__':
working_dir = os.path.abspath('../logs')#sys.argv[1]
files = os.listdir(working_dir)
users = {}
nick_re = re.compile(r'<span\s+class\s*=\s*"self.*">&lt;(.+)&gt;</span>')
for filename in files:
with open(working_dir + '\\' + filename, 'r') as file:
for line in file:
nick_match = nick_re.search(line)
if nick_match:
try:
users[nick_match.group(1)] += 1;
except(KeyError):
users[nick_match.group(1)] = 1
sresu = dict((val, name) for name, val in users.iteritems())
for name, val in sorted(sresu.iteritems(),reverse=True):#sresu.iteritems():
print name, ':', val