forked from dantman/pywikia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitwarning.py
39 lines (35 loc) · 1.15 KB
/
splitwarning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
"""Splits a interwiki.log file into chunks of warnings separated by language"""
#
# (C) Rob W.W. Hooft, 2003
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id$'
#
import wikipedia
import codecs
import re
wikipedia.stopme() # No need to have me on the stack - I don't contact the wiki
files={}
count={}
# TODO: Variable log filename
fn = wikipedia.config.datafilepath("logs", "interwiki.log")
logFile = codecs.open(fn, 'r', 'utf-8')
rWarning = re.compile('WARNING: (?P<family>.+?): \[\[(?P<code>.+?):.*')
for line in logFile:
m = rWarning.match(line)
if m:
family = m.group('family')
code = m.group('code')
if code in wikipedia.getSite().languages():
if not code in files:
files[code] = codecs.open(
wikipedia.config.datafilepath('logs',
'warning-%s-%s.log' % (family, code)),
'w', 'utf-8')
count[code] = 0
files[code].write(line)
count[code] += 1
for code in files.keys():
print '*%s (%d)' % (code, count[code])