Utente:Sirbot/Script
monitoraggioimmagini.py modificato
Basato su Utente:BimBot/Scripts#monitoraggioimmagini.py
#!/usr/bin/env python
# -*- utf-8 -*-
"""
README: Todo
"""
#
# (C) Pietrodn, 2007
# (C) Sirabder87, 2008
# (C) Filnik, 2008
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: $'
#
import wikipedia, catlib, re
def main():
always = False
for arg in wikipedia.handleArgs():
if arg.startswith("-always"):
always = True
site = wikipedia.getSite()
category_name = 'Categoria:Progetto:Musica/Punk/Tabella monitoraggio automatico - immagini nc'
categoria = catlib.Category(site, category_name)
discussioni = categoria.articles()
for page in discussioni:
if not page.isTalkPage():
continue
associatedPage = page.toggleTalkPage()
try:
pageText = associatedPage.get()
except Wikipedia.Error, e:
wikipedia.output(e) # Print the error and skip
continue
match = re.search('(\[\[(image|immagine):|Fotografia ?= ?.)', pageText, re.IGNORECASE)
if match == None:
wikipedia.output(">>>>> %s <<<<<" % associatedPage.title())
try:
talkText = page.get()
except Wikipedia.Error, e:
wikipedia.output(e) # Print the error and skip
continue
newTalkText = re.sub('\|\n? *?[Ii]mmagini= *?\n', '|Immagini=d\n', talkText)
if talkText != newTalkText:
wikipedia.showDiff(talkText, newTalkText)
if not always:
choice = wikipedia.inputChoice(u"Apply the changes?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
else:
choice = 'y'
if choice in ['A', 'a']:
always = True
choice = 'y'
if choice in ['Y', 'y']:
try:
page.put(newTalkText, u'Bot: Non ci sono immagini: valutazione "d"')
except Wikipedia.Error, e:
wikipedia.output(e) # Print the error and skip
continue
if __name__ == "__main__":
try:
main()
finally:
wikipedia.stopme()