User:Bdamokos/nincsforras3.py
A Wikipédiából, a szabad lexikonból.
Kép licenc/ nincslicenc megadó bot. Végigmegy az összes kép oldalon, és amelyiknél nincs licenc, ott megmutatja a kép leírását (a képet magát sajnos nem), és felajánlja, hogy rátegye a nincslicenc sablont. Ha nemet mondunk erre, akkor kézzel meg lehet adni, milyen sablont tegyen rá (a kapcsos zárójelek nélkül). Elméletileg felismeri, ha egy kép engedély alapján van fenn a wikin, és arra a {{jogvédett}} sablon feltételét ajánlja fel (amin később pótolni kell a feltételeket kézzel). Hasonlóan a saját képekre néha felajánlja a {{saját kép}} sablont.
<nowiki>
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This is not a complete bot; rather, it is a template from which simple
bots can be made. Change workon to edit the contents of a Wikipedia page,
save the result as mybot.py, and then just run:
python mybot.py
to have your change be done on all pages of the wiki. If that takes too
long to work in one stroke, run:
python mybot.py Pagename
to do all pages starting at pagename.
There is one standard command line option:
-test: Ask for input after every change
"""
import wikipedia
import pagegenerators
import sys, re
bracket="{"
re_nincslicenc=re.compile(ur"\{\{" )
re_engedely=re.compile(ur"engedély" )
re_sajat=re.compile(ur"saját" )
mysite = wikipedia.getSite()
namespaces = 6
gen = pagegenerators.AllpagesPageGenerator(start ='!', namespace = 6)
generator = pagegenerators.PreloadingGenerator(gen)
acceptall = False
for page in generator:
try:
text = page.get()
l=re_nincslicenc.search(text)
if l:
#wikipedia.output(u"HIBA: A %s lapon már van licenc" % page.title())
continue
e=re_engedely.search(text)
if e:
text1 = text
text1 +="\n"
text1 +=u"{{jogvédett}}"
colors = [None] * 5 + [13] * len(page.title()) + [None] * 4
wikipedia.output(u'\n>>> %s <<<' % page.title(), colors = colors)
wikipedia.output(u" %s " % text)
wikipedia.showDiff(text, text1)
if not acceptall:
choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes',
'No', 'All'], ['y', 'N', 'a'], 'N')
if choice in ['a', 'A']:
acceptall = True
if acceptall or choice in ['y', 'Y']:
wikipedia.output(u"\nVáltoztatások:\n")
wikipedia.showDiff(text, text1)
page.put(text1, u"engedély sablon ({{sl|jogvédett}}) elhelyezése, kérlek pótold
a pontos feltételeket")
if choice in ['N', 'n']:
sablon = wikipedia.input(u'Milyen sablont kapjon?')
text2= text
if sablon:
text2 += "\n" + u"{{" + sablon + u"}}"
wikipedia.showDiff(text, text2)
page.put(text2, u"képlicenc elhelyezése: %s" % sablon)
continue
s=re_sajat.search(text)
if s:
text1 = text
text1 +="\n"
text1 +=u"{{saját kép}}"
colors = [None] * 5 + [13] * len(page.title()) + [None] * 4
wikipedia.output(u'\n>>> %s <<<' % page.title(), colors = colors)
wikipedia.output(u" %s " % text)
if not acceptall:
choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes',
'No', 'All'], ['y', 'N', 'a'], 'N')
if choice in ['a', 'A']:
acceptall = True
if acceptall or choice in ['y', 'Y']:
wikipedia.output(u"\nVáltoztatások:\n")
wikipedia.showDiff(text, text1)
page.put(text1, u"saját kép sablon elhelyezése, kérlek pótold a pontos
feltételeket")
if choice in ['N', 'n']:
sablon = wikipedia.input(u'Milyen sablont kapjon?')
if sablon:
text2= text
text2 += "\n" + u"{{" + sablon + u"}}"
wikipedia.showDiff(text, text2)
page.put(text2, u"képlicenc elhelyezése: %s" % sablon)
continue
text1 = text
text1 +="\n"
text1 +=u"{{nincslicenc|~~~~~}}"
colors = [None] * 5 + [13] * len(page.title()) + [None] * 4
wikipedia.output(u'\n>>> %s <<<' % page.title(), colors = colors)
wikipedia.output(u" %s " % text)
wikipedia.showDiff(text, text1)
if not acceptall:
choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes',
'No', 'All'], ['y', 'N', 'a'], 'N')
if choice in ['a', 'A']:
acceptall = True
if acceptall or choice in ['y', 'Y']:
wikipedia.output(u"\nVáltoztatások:\n")
wikipedia.showDiff(text, text1)
page.put(text1, u"Nincslicenc sablon elhelyezése")
if choice in ['N', 'n']:
sablon = wikipedia.input(u'Milyen sablont kapjon?')
if sablon:
text2= text
text2 += "\n" + u"{{" + sablon + u"}}"
wikipedia.showDiff(text, text2)
page.put(text2, u"képlicenc elhelyezése: %s" % sablon)
except wikipedia.NoPage:
wikipedia.output(u"HIBA: Nem találom a %s lapot" % page.title())
continue
finally:
wikipedia.stopme()
</nowiki>

