Advertisement
Guest User

Codi Viquitexts

a guest
Nov 25th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.87 KB | None | 0 0
  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.  
  27. import re
  28. from datetime import datetime, date
  29.  
  30. import pywikibot as wikipedia
  31. #import query as query
  32. import pywikibot.data.api
  33.  
  34. site = wikipedia.Site('ca','wikisource')
  35. punts = {}
  36. vali = {}
  37. revi = {}
  38. llibres = []
  39. for x in range(1859, 1908):
  40.     ll = u'Jochs Florals de Barcelona en '+str(x)+u'.djvu'
  41.     llibres.append(ll)
  42. begin = 1
  43. end = [184, 152, 184,149,154,137,212,151,227,320, 329, 237, 198,127, 153, 169, 291, 323, 241, 219, 468, 303, 133, 127, 163, 0, 0, 183, 241, 0, 225, 265, 284, 346, 0, 0, 0, 0, 465, 293, 169, 251, 165, 175, 247, 295, 202, 138, 270]
  44. if len(llibres) == len(end):
  45.     print "Perfecte son iguals"
  46. i = 0
  47. for llibre in llibres:
  48.     print llibre
  49.     for pag in range(begin, end[i]+1):
  50.         print pag
  51.         params = {
  52.                 'action'    :'query',
  53.                 'prop'      :'revisions',
  54.                 'titles'    :u'Page:%s/%d' % (llibre, pag),
  55.                 'rvlimit'   :'50',
  56.                 'rvprop'    :'user|timestamp|content',
  57.         }
  58.         data = pywikibot.data.api.CachedRequest(5, **params).submit()
  59.         try:    
  60.             revs = data["query"]["pages"].values()[0]["revisions"][::-1]
  61.         except KeyError:
  62.             continue
  63.         old = None
  64.         oldUser = None
  65.         oldData = None
  66.         for rev in revs:
  67.             data = datetime.strptime(rev["timestamp"], '%Y-%m-%dT%H:%M:%SZ')
  68.             user = rev["user"]
  69.             txt = rev["*"]
  70.             a,b = re.findall('<pagequality level="(\d)" user="(.*?)" />', txt)[0]
  71.             a = int(a)
  72.             b = user
  73.             if a == 3 and old < 3 and data >= datetime(2014, 11, 14, 0, 0, 0) and data < datetime(2014, 11, 25, 0, 0, 0):
  74.                 print u"%s proofreads the page %d." % (b, pag)
  75.                 if old == None: print u"Page doesn't exist before."
  76.                 punts[b] = punts.get(b, 0)+2
  77.                 revi[b] = revi.get(b, 0)+1
  78.             if a == 3 and old == 4 and data >= datetime(2014, 11, 14, 0, 0, 0) and data < datetime(2014, 11, 25, 0, 0, 0):
  79.                 if (oldData >= datetime(2014, 11, 14, 0, 0, 0) and oldData < datetime(2014, 11, 25, 0, 0, 0)):
  80.                     punts[oldUser] = punts.get(oldUser, 0)-1
  81.                     vali[oldUser] = vali.get(oldUser, 0)-1
  82.             if a == 4 and old == 3 and data >= datetime(2014, 11, 14, 0, 0, 0) and data < datetime(2014, 11, 25, 0, 0, 0):
  83.                 print u"%s validates page %d." % (b, pag)
  84.                 punts[b] = punts.get(b, 0)+1
  85.                 vali[b] = vali.get(b, 0)+1
  86.             if a < 3 and old == 3 and data >= datetime(2014, 11, 14, 0, 0, 0) and data < datetime(2014, 11, 25, 0, 0, 0):
  87.                 if (oldData >= datetime(2014, 11, 14, 0, 0, 0) and oldData < datetime(2014, 11, 25, 0, 0, 0)):
  88.                     punts[oldUser] = punts.get(oldUser, 0)-2
  89.                     revi[oldUser] = vali.get(oldUser, 0)-1
  90.                    
  91.                
  92.             old = a
  93.             oldUser = b
  94.             oldData = data
  95.         print "-------"
  96.     ++i
  97. print "punt",sorted(punts.iteritems(), key=lambda x: x[1], reverse=True)
  98. print "vali",sorted(vali.iteritems(), key=lambda x: x[1], reverse=True)
  99. print "revi",sorted(revi.iteritems(), key=lambda x: x[1], reverse=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement