daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Dec 17 18:58:19 2018
  4.  
  5. @author: cedtr
  6. """
  7.  
  8. ADJ = 'adjectif'
  9. NOM = 'nom'
  10.  
  11.  
  12. import pywikibot
  13. site = pywikibot.Site()
  14. special_chars = set('ĉĝĥĵŝŭ')
  15.  
  16. def get_page_j(page_name, prononciation, cat_type):
  17.     cle = ""
  18.     if set(page_name) & special_chars != set():
  19.         x_page_name = page_name.replace('ĉ', 'cx').replace('ĝ', 'gx').replace('ĥ', 'hx').replace('ĵ', 'jx').replace('ŝ', 'sx').replace('ŭ', 'ux')
  20.         cle = f"\n\n{{{{clé de tri|{x_page_name}j}}}}"
  21.     return f"""== {{{{langue|eo}}}} ==
  22. === {{{{S|{cat_type}|eo|flexion}}}} ===
  23. {{{{eo-rég|{prononciation}}}}}
  24. '''{page_name}j''' {{{{pron|{prononciation}j|eo}}}}
  25. # ''Nominatif pluriel de ''[[{page_name}#eo|{page_name}]].""" + cle
  26.  
  27. def get_page_jn(page_name, prononciation, cat_type):
  28.     cle = ""
  29.     if set(page_name) & special_chars != set():
  30.         x_page_name = page_name.replace('ĉ', 'cx').replace('ĝ', 'gx').replace('ĥ', 'hx').replace('ĵ', 'jx').replace('ŝ', 'sx').replace('ŭ', 'ux')
  31.         cle = f"\n\n{{{{clé de tri|{x_page_name}jn}}}}"
  32.     return f"""== {{{{langue|eo}}}} ==
  33. === {{{{S|{cat_type}|eo|flexion}}}} ===
  34. {{{{eo-rég|{prononciation}}}}}
  35. '''{page_name}jn''' {{{{pron|{prononciation}jn|eo}}}}
  36. # ''Accusatif pluriel de ''[[{page_name}#eo|{page_name}]].""" + cle
  37.  
  38. def get_page_n(page_name, prononciation, cat_type):
  39.     cle = ""
  40.     if set(page_name) & special_chars != set():
  41.         x_page_name = page_name.replace('ĉ', 'cx').replace('ĝ', 'gx').replace('ĥ', 'hx').replace('ĵ', 'jx').replace('ŝ', 'sx').replace('ŭ', 'ux')
  42.         cle = f"\n\n{{{{clé de tri|{x_page_name}n}}}}"
  43.     return f"""== {{{{langue|eo}}}} ==
  44. === {{{{S|{cat_type}|eo|flexion}}}} ===
  45. {{{{eo-rég|{prononciation}}}}}
  46. '''{page_name}n''' {{{{pron|{prononciation}n|eo}}}}
  47. # ''Accusatif singulier de ''[[{page_name}#eo|{page_name}]].""" + cle
  48.  
  49. def get_page(flexion):
  50.     if flexion == "j":
  51.         return get_page_j
  52.     if flexion == "jn":
  53.         return get_page_jn
  54.     if flexion == "n":
  55.         return get_page_n
  56.  
  57. def create_flexion(page_name, flexion, prononciation, cat_type, force):
  58.     page = pywikibot.Page(site, f"{page_name}{flexion}")
  59.     if force or page.text == "":
  60.         page.text = get_page(flexion)(page_name, prononciation, cat_type)
  61.         page.save("Création automatique de la flexion.", watch="unwatch")
  62.     else:
  63.         print(f"{page_name}{flexion} already exists.")
  64.  
  65.  
  66. def is_missing_flexions(page_name):
  67.     page = pywikibot.Page(site, page_name)
  68.     templates = page.raw_extracted_templates
  69.     eo_reg = [t[0] for t in templates if t[0] in ["eo-rég", "eo-rég-v"]]
  70.     if len(eo_reg) == 0:
  71.         return False
  72.     page_j = pywikibot.Page(site, f"{page_name}j").text == ""
  73.     page_jn = pywikibot.Page(site, f"{page_name}jn").text == ""
  74.     page_n = pywikibot.Page(site, f"{page_name}n").text == ""
  75.     return eo_reg[0] == "eo-rég" and (page_j or page_jn or page_n)
  76.  
  77. def create_flexions(page_name, prononciation, cat_type, force):
  78.     create_flexion(page_name, "j", prononciation, cat_type, force)
  79.     create_flexion(page_name, "jn", prononciation, cat_type, force)
  80.     create_flexion(page_name, "n", prononciation, cat_type, force)
  81.  
  82. WORDS = [('acetimetro', 'a.t͡se.ti.ˈme.tro', NOM, False),
  83.          ]
  84.  
  85. for word, prononciation, cat_type, force in WORDS:
  86.     create_flexions(word, prononciation, cat_type, force)
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