2011年7月3日 星期日

Wiktionary - Recent changes [en]: User:Flubot/cedillaBot

Wiktionary - Recent changes [en]
Track the most recent changes to the wiki in this feed.

User:Flubot/cedillaBot
3 Jul 2011, 10:08 pm

Created page with "==cedillaBot== <source lang=python> #!/usr/bin/python # -*- coding: utf-8 -*- import wikipedia, pagegenerators, catlib import re class cedillabot: def __init__(self, gener..."

New page

==cedillaBot==
<source lang=python>
#!/usr/bin/python
# -*- coding: utf-8 -*-

import wikipedia, pagegenerators, catlib
import re

class cedillabot:

def __init__(self, generator, site, debug_bul = True):
self.generator = generator
self.debug_bul = debug_bul
self.site = site

def run(self):
romanian = re.compile('==Romanian==')
glossa = re.compile('^==([^=]+)==')
romfound = False
etymologyfound = False
etymology = re.compile('===Etymology===')
epikefalida = re.compile('^===(.*)===$')
s1 = re.compile(u'ş')
s2 = re.compile(u'Ş')
t1 = re.compile(u'ţ')
t2 = re.compile(u'Ţ')

# Here is defined the entry to modificate

for p in self.generator:
titlos = p.title()
print(titlos)
page = wikipedia.Page(wikipedia.getSite(), titlos)
arxiko = page.get(get_redirect=True)

marker = '@@'
while marker in arxiko:
marker += '@'

site = self.site
interwiki = wikipedia.getLanguageLinks(arxiko, insite = site)
textnoiws = wikipedia.removeLanguageLinks(arxiko.replace(marker,'').strip(), site = self.site) + site.family.category_text_separator

# Replace
romfound = False
etymologyfound = False
seires = textnoiws.split("\n")
kainoyrio = []
for seira in seires:
if romanian.search(seira):
romfound = True
etymologyfound = False
elif etymology.search(seira):
etymologyfound = True
elif epikefalida.search(seira):
etymologyfound = False
elif glossa.search(seira):
romfound = False
if romfound:
seira = t1.sub(u'ț', seira)
seira = t2.sub(u'Ț', seira)
if romfound and not etymologyfound:
seira = s1.sub(u'ș', seira)
seira = s2.sub(u'Ș', seira)
kainoyrio.append(seira)
keimeno1 = "\n".join(kainoyrio)
keimeno = wikipedia.replaceLanguageLinks(keimeno1, interwiki, site = self.site)

# Save page
wikipedia.setAction(u'bot:changing cedillas with commas in Romanian entries')

if keimeno1 != textnoiws:
# Show the title of the page we're working on.
# Highlight the title in purple.
wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<" % page.title())
## show what was changed
wikipedia.showDiff(page.get(), keimeno)
#choice= 'y'
if self.debug_bul:
choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['yes', 'No', 'all'], ['y', 'N', 'a'], 'N')
if choice == 'a':
choice = 'y'
self.debug_bul = False
elif choice != 'y':
choice='n'
if choice == 'y':
try:
# Save the page
page.put(keimeno)
except wikipedia.IsRedirectPage:
wikipedia.output(u'Skipping %s because it is a redirect' % (page.title()))
except wikipedia.EditConflict:
wikipedia.output(u'Skipping %s because of edit conflict' % (page.title()))
except wikipedia.SpamfilterError, error:
wikipedia.output(u'Cannot change %s because of spam blacklist entry %s' % (page.title(), error.url))
return 0


def main():
gen = None
pageTitle = []
for arg in wikipedia.handleArgs():
if arg:
if arg.startswith('-file:'):
gen = pagegenerators.TextfilePageGenerator(arg[6:])
elif arg.startswith('-cat:'):
cat = catlib.Category(wikipedia.getSite(), arg[5:])
gen = pagegenerators.CategorizedPageGenerator(cat)
else:
pageTitle.append(arg)

if pageTitle:
page = wikipedia.Page(wikipedia.getSite(), ' '.join(pageTitle))
gen = iter([page])
if not gen:
wikipedia.showHelp('touch')
else:
preloadingGen = pagegenerators.PreloadingGenerator(gen)
bot = cedillabot(preloadingGen, wikipedia.getSite())
bot.run()

if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()
</source>

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed.

沒有留言:

張貼留言