SHARE
TWEET

Untitled

a guest Nov 24th, 2013 150 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.                 try:
  61.                         revs = data["query"]["pages"].values()[0]["revisions"][::-1]
  62.                 except KeyError:
  63.                         continue
  64.                 old = None
  65.                 oldUser = None
  66.                 oldData = None
  67.                 for rev in revs:
  68.                         data = datetime.strptime(rev["timestamp"], '%Y-%m-%dT%H:%M:%SZ')
  69.                         user = rev["user"]
  70.                         txt = rev["*"]
  71.                         a,b = re.findall('<pagequality level="(\d)" user="(.*?)" />', txt)[0]
  72.                         a = int(a)
  73.                         b = user
  74.                         if a == 3 and old < 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
  75.                                 print u"Llibre %s" % llibre
  76.                                 print u"%s proofreads the page %d." % (b, pag)
  77.                                 if old == None: print u"Page doesn't exist before."
  78.                                 else: print u"Page change from %d to %d quality." % (old, a)
  79.                                 punts[b] = punts.get(b, 0)+3
  80.                         if a == 3 and old == 4 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
  81.                                 if (oldData >= datetime(2013, 11, 24, 0, 0, 0) and oldData < datetime(2013, 12, 2, 0, 0, 0)):
  82.                                         punts[oldUser] = punts.get(oldUser, 0)-1
  83.                         if a == 4 and old == 3 and data >= datetime(2013, 11, 24, 0, 0, 0) and data < datetime(2013, 12, 2, 0, 0, 0):
  84.                                 print u"%s validates page %d." % (b, pag)
  85.                                 punts[b] = punts.get(b, 0)+1
  86.                         old = a
  87.                         oldUser = b
  88.                         oldData = data
  89.                 print "-------"
  90.         i+= 1
  91. punts = sorted(punts.iteritems(), key=operator.itemgetter(1), reverse=True)
  92. print u"{| Class=\"wikitable sortable\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" align=\"center\""
  93. print u"! Posició || Usuari || Punts"
  94. j = 1
  95. for punt in punts:
  96.         print "|-----"
  97.         print ("| %d ||[[User:"+punt[0]+"|"+punt[0]+"]] || %d") % (j, punt[1])
  98.         j += 1
  99. print u"|}"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top