Fetching contributors…
Cannot retrieve contributors at this time
executable file 112 lines (84 sloc) 3.09 KB
# -*- coding: utf-8 -*-
This bot goes over multiple pages of a wiki, and edits them without changes.
This is for example used to get category links in templates
This script understands various command-line arguments:
-purge Do not touch but purge the page
-botflag Force botflag in case of edits with changes.
# (C) Pywikibot team, 2009-2018
# Distributed under the terms of the MIT license.
from __future__ import absolute_import, division, unicode_literals
import pywikibot
from pywikibot import pagegenerators
from import MultipleSitesBot
from pywikibot.exceptions import ArgumentDeprecationWarning
from import issue_deprecation_warning
docuReplacements = {'&params;': pagegenerators.parameterHelp}
class TouchBot(MultipleSitesBot):
"""Page touch bot."""
def __init__(self, generator, **kwargs):
"""Initialize a TouchBot instance with the options and generator."""
'botflag': False,
super(TouchBot, self).__init__(generator=generator, **kwargs)
def treat(self, page):
"""Touch the given page."""
except (pywikibot.NoCreateError, pywikibot.NoPage):
pywikibot.error('Page {0} does not exist.'
except pywikibot.LockedPage:
pywikibot.error('Page {0} is locked.'
except pywikibot.PageNotSaved:
pywikibot.error('Page {0} not saved.'
class PurgeBot(MultipleSitesBot):
"""Purge each page on the generator."""
def treat(self, page):
"""Purge the given page."""
pywikibot.output('Page {0}{1} purged'.format(
page.title(as_link=True), '' if page.purge() else ' not'))
def main(*args):
Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
@param args: command line arguments
@type args: unicode
gen = None
options = {}
# Process global args and prepare generator args parser
local_args = pywikibot.handle_args(args)
gen_factory = pagegenerators.GeneratorFactory()
bot_class = TouchBot
for arg in local_args:
if arg == '-purge':
bot_class = PurgeBot
elif arg == '-redir':
'\n-redir', None, 1, ArgumentDeprecationWarning,
elif not gen_factory.handleArg(arg) and arg.startswith('-'):
# -botflag
options[arg[1:].lower()] = True
gen = gen_factory.getCombinedGenerator(preload=True)
if gen:
bot = bot_class(generator=gen, **options)
return True
return False
if __name__ == '__main__':