View difference between Paste ID: gkPVLDHB and aMLGXiLS
SHOW: | | - or go back to the newest paste.
1
# -*- coding: utf-8 -*-
2
3
"""
4
The MIT License (MIT)
5
6
Copyright (c) 2013 Joan Creus <joan.creus.c@gmail.com>
7
8
Permission is hereby granted, free of charge, to any person obtaining a copy
9
of this software and associated documentation files (the "Software"), to deal
10
in the Software without restriction, including without limitation the rights
11
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
copies of the Software, and to permit persons to whom the Software is
13
furnished to do so, subject to the following conditions:
14
15
The above copyright notice and this permission notice shall be included in
16
all copies or substantial portions of the Software.
17
18
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
THE SOFTWARE.
25
"""
26
import sys
27
reload(sys)
28
sys.setdefaultencoding("utf-8")
29
30
import re
31
from datetime import datetime, date
32
33
import pywikibot as wikipedia
34
import pywikibot.compat.query as query
35
import pywikibot.data.api
36
import operator
37
38
site = wikipedia.getSite('ca','wikisource')
39
punts = {}
40
"""
41
Change the books of Catalan contest for your local books. Pex. "Mar y cel (1903).djvu" --> "Foggerty.djvu"
42
"""
43
llibres = [u'Mar y cel (1903).djvu', u'Obres completes de Narcís Oller VI - La bogeria (1928).djvu', u'Obres completes d\'En Joan Maragall - Poesies II (1918).djvu']
44
begin = 1
45
"""
46
Put your local last page of books in the right order. Pex: Foggerty.djvu is 376"
47
"""
48
end = [162, 348, 332]
49
i = 0
50
for llibre in llibres:
51
	for pag in range(begin, end[i]+1):
52
		params = {
53
				'action'	:'query',
54
				'prop'		:'revisions',
55
				'titles'	:u'Pàgina:%s/%d' % (llibre, pag),
56
				'rvlimit'       :'50',
57
				'rvprop'	:'user|timestamp|content',
58
		}
59
		data = pywikibot.data.api.CachedRequest(5, site=site, **params).submit()
60
		revs = data["query"]["pages"].values()[0]["revisions"][::-1]
61
		old = None
62
		oldUser = None
63
		oldData = None
64
		for rev in revs:
65
			data = datetime.strptime(rev["timestamp"], '%Y-%m-%dT%H:%M:%SZ')
66
			user = rev["user"]
67
			txt = rev["*"]
68
			a,b = re.findall('<pagequality level="(\d)" user="(.*?)" />', txt)[0]
69
			a = int(a)
70
			b = user
71
			if a == 3 and old < 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
72
				print u"Llibre %s" % llibre
73
				print u"%s proofreads the page %d." % (b, pag)
74
				if old == None: print u"Page doesn't exist before."
75
				else: print u"Page change from %d to %d quality." % (old, a)
76
				punts[b] = punts.get(b, 0)+3
77
			if a == 3 and old == 4 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
78
				if (oldData >= datetime(2013, 11, 24, 0, 0, 0) and oldData < datetime(2013, 12, 2, 0, 0, 0)):
79
					punts[oldUser] = punts.get(oldUser, 0)-1
80
			if a == 4 and old == 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
81
				print u"%s validates page %d." % (b, pag)
82
				punts[b] = punts.get(b, 0)+1
83
			old = a
84
			oldUser = b
85
			oldData = data
86
		print "-------"
87
	i+= 1
88
punts = sorted(punts.iteritems(), key=operator.itemgetter(1), reverse=True)
89
print u"{| Class=\"wikitable sortable\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\"" 
90
print u"! Posició || Usuari || Punts"
91
j = 1
92
for punt in punts:
93
	print "|-----"
94
	print ("| %d ||[[User:"+punt[0]+"|"+punt[0]+"]] || %d") % (j, punt[1])
95
	j += 1
96
print u"|}"