daily pastebin goal
69%
SHARE
TWEET

Untitled

a guest Nov 9th, 2015 65 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. import sys
  9.  
  10. paraules = [u' Arròs ', u' arròs '] # NO TOCAR AQUESTES LLISTES
  11. paraules_plural = [' arrossos ']
  12. paraules_punt_sing = [u' Arròs.', u' arròs.', u' arròs,', u' Arròs,']
  13. paraules_coma_sing = [u' arròs,', u' Arròs,']
  14. paraules_punt_pl = [' arrossos.']
  15.  
  16. def main(pag):
  17.     for paraula in paraules:
  18.         if paraula.replace(' ', '') in str(pag).decode('utf-8'):
  19.             return
  20.     text = pag.text
  21.     coincidencies = []
  22.     for paraula in paraules:
  23.         if paraula in text:
  24.             coincidencies.append(paraula)
  25.     for paraula in paraules_plural:
  26.         if paraula in text:
  27.             coincidencies.append(paraula)
  28.     for paraula in paraules_punt_sing:
  29.         if paraula in text:
  30.             coincidencies.append(paraula)
  31.     for paraula in paraules_punt_pl:
  32.         if paraula in text:
  33.             coincidencies.append(paraula)              
  34.     print("\033[1m%s\033[0m: \033[1m%s\033[0m coincidències" % (pag, len(coincidencies)))
  35.     print("COINCIDENCIES:" + str(coincidencies))
  36.     if len(coincidencies) == 0:
  37.         print("Me la salto")
  38.         return
  39.     for paraula in paraules:
  40.         u_noutext = text.replace(paraula, ' [[' + paraula.replace(' ', '') + ']] ')
  41.     for paraula in paraules_plural:
  42.         dos_noutext = u_noutext.replace(paraula, ' [[' + paraules[0].replace(' ', '') + '|' + paraula.replace(' ', '') + ']] ')
  43.     for paraula in paraules_punt_sing:
  44.         tres_noutext = dos_noutext.replace(paraula, ' [[' + paraula.replace('\.', '').replace(' ', '') + ']].')
  45.     for paraula in paraules_coma_sing:
  46.         quatre_noutext = tres_noutext.replace(paraula, ' [[' + paraula.replace(' ', '').replace(',', '') + ']],')        
  47.     for paraula in paraules_punt_pl:
  48.         noutext = quatre_noutext.replace(paraula, ' [[' + paraules[0].replace(' ', '') + '|' + paraula.replace('\.', '').replace(' ', '').replace(',', '') + ']].')
  49.     pag.text = noutext
  50.     pag.save(u'Bot: Afegint enllaços per la paraula %s' % paraules[0])
  51.  
  52. if __name__ == '__main__':
  53.     allpages = pg.AllpagesPageGenerator(site=pwb.Site("ca", "wikiquote"), start="!", namespace=0, includeredirects = True)
  54.     pages = pg.PreloadingGenerator(allpages, pageNumber = 100)
  55.     for page in pages:
  56.         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