daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Nov 6th, 2015 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2.  
  3. import pywikibot as pwb
  4. from pywikibot import pagegenerators as pg
  5. import urllib
  6. import json
  7. import re
  8.  
  9. enllac = ' Peix ' # La primera lletra en majusucla!!!!
  10. plural = ' peixos '
  11. enllacpunt = ' Peix.'
  12. pluralpunt = ' peixos.'
  13. enllac_min = enllac.lower()
  14. enllacpunt_min = enllacpunt.lower()
  15.  
  16. def main(pag):
  17.     site = pwb.Site('ca', 'wikiquote')
  18.     page = pwb.Page(site, pag)
  19.     text = page.text
  20.     coincidencies = text.count(enllac) + text.count(enllac_min)
  21.     print(u"%s: he trobat %s coincidències de la paraula %s i %s." % (pag, coincidencies, enllac, enllac_min))
  22.     if coincidencies == 0:
  23.         print(u"Em salto la pàgina")
  24.         return
  25.     noutext = text.replace(enllac, ' [[' + enllac.replace(' ', '') + ']] ').replace(enllac, ' [[' + enllac_min.replace(' ', '') + ']] ').replace(plural, ' [[' + enllac_min.replace(' ', '') + '|peixos]] ').replace(enllacpunt, ' [[' + enllac.replace(' ', '') + ']].').replace(enllacpunt_min, ' [[' + enllac_min.replace(' ', '') + ']].').replace(pluralpunt, ' [[' + enllac_min.replace(' ', '') +  '|' + plural.replace(' ', '') + ']].')
  26.     page.text = noutext
  27.     page.save(u'Bot: Afegint enllaços per la paraula %s' % enllac_min)
  28.  
  29. if __name__ == '__main__':
  30.     allpages = pg.AllpagesPageGenerator(site=pwb.Site("ca", "wikiquote"), start="!", namespace=0, includeredirects = True)
  31.     pages = pg.PreloadingGenerator(allpages, pageNumber = 100)
  32.     for page in pages:
  33.         main(page)
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