Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- The MIT License (MIT)
- Copyright (c) 2013 Joan Creus <joan.creus.c@gmail.com>
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- """
- import sys
- reload(sys)
- sys.setdefaultencoding("utf-8")
- import re
- from datetime import datetime, date
- import pywikibot as wikipedia
- import pywikibot.compat.query as query
- import pywikibot.data.api
- import operator
- site = wikipedia.getSite('ca','wikisource')
- punts = {}
- """
- Change the books of Catalan contest for your local books. Pex. "Mar y cel (1903).djvu" --> "Foggerty.djvu"
- """
- 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']
- begin = 1
- """
- Put your local last page of books in the right order. Pex: Foggerty.djvu is 376"
- """
- end = [162, 348, 332]
- i = 0
- for llibre in llibres:
- for pag in range(begin, end[i]+1):
- params = {
- 'action' :'query',
- 'prop' :'revisions',
- 'titles' :u'Pàgina:%s/%d' % (llibre, pag),
- 'rvlimit' :'50',
- 'rvprop' :'user|timestamp|content',
- }
- data = pywikibot.data.api.CachedRequest(5, site=site, **params).submit()
- try:
- revs = data["query"]["pages"].values()[0]["revisions"][::-1]
- except KeyError:
- continue
- old = None
- oldUser = None
- oldData = None
- for rev in revs:
- data = datetime.strptime(rev["timestamp"], '%Y-%m-%dT%H:%M:%SZ')
- user = rev["user"]
- txt = rev["*"]
- a,b = re.findall('<pagequality level="(\d)" user="(.*?)" />', txt)[0]
- a = int(a)
- b = user
- if a == 3 and old < 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
- print u"Llibre %s" % llibre
- print u"%s proofreads the page %d." % (b, pag)
- if old == None: print u"Page doesn't exist before."
- else: print u"Page change from %d to %d quality." % (old, a)
- punts[b] = punts.get(b, 0)+3
- if a == 3 and old == 4 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
- if (oldData >= datetime(2013, 11, 24, 0, 0, 0) and oldData < datetime(2013, 12, 2, 0, 0, 0)):
- punts[oldUser] = punts.get(oldUser, 0)-1
- if a == 4 and old == 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
- print u"%s validates page %d." % (b, pag)
- punts[b] = punts.get(b, 0)+1
- old = a
- oldUser = b
- oldData = data
- print "-------"
- i+= 1
- punts = sorted(punts.iteritems(), key=operator.itemgetter(1), reverse=True)
- print u"{| Class=\"wikitable sortable\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\""
- print u"! Posició || Usuari || Punts"
- j = 1
- for punt in punts:
- print "|-----"
- print ("| %d ||[[User:"+punt[0]+"|"+punt[0]+"]] || %d") % (j, punt[1])
- j += 1
- print u"|}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement