2 # -*- coding: utf-8 -*-
4 This is not a complete bot; rather, it is a template from which simple
5 bots can be made. You can rename it to mybot.py, then edit it in
8 The following parameters are supported:
12 -dry If given, doesn't do any real changes, but only shows
13 what would have been changed.
15 All other parameters will be regarded as part of the title of a single page,
16 and the bot will only work on that single page.
19 # (C) Pywikipedia bot team, 2006-2010
21 # Distributed under the terms of the MIT license.
23 __version__
= '$Id: basic.py 8278 2010-06-11 17:01:24Z xqt $'
26 import wikipedia
as pywikibot
29 # This is required for the text that is shown when you run this script
30 # with the parameter -help.
32 '¶ms;': pagegenerators
.parameterHelp
36 # Edit summary message that should be used.
37 # NOTE: Put a good description here, and add translations, if possible!
39 'en': u
'Robot correcting misplaced [[WP:WPAFC|AFC]] submission',
42 def __init__(self
, generator
, dry
):
44 Constructor. Parameters:
45 * generator - The page generator that determines on which pages
47 * dry - If True, doesn't do any real changes, but only shows
48 what would have been changed.
50 self
.generator
= generator
53 # Set the edit summary message
54 self
.summary
= pywikibot
.translate(pywikibot
.getSite(), self
.msg
)
57 for page
in self
.generator
:
60 def treat(self
, page
):
61 namespace_pg
= page
.namespace()
65 tmp
= page
.titleWithoutNamespace()
66 tmp
= tmp
.replace(tmp
.split("/")[0]+"/","")
68 tmp
= "Wikipedia talk:Articles for creation/" + tmp
70 if page
.title() == "Wikipedia:Files for upload":
73 elif page
.title() == "Wikipedia:Articles for creation/Redirects":
77 self
.dry
= self
.perdry
78 self
.doNotMove
= False
81 page
.move(newPageTitle
, self
.summary
, throttle
=True)
84 if not self
.doNotMove
:
85 print "I would have moved " + tg
+ " to: " + tmp
88 # This factory is responsible for processing command line arguments
89 # that are also used by other scripts and that determine on which pages
91 genFactory
= pagegenerators
.GeneratorFactory()
92 # The generator gives the pages that should be worked upon.
94 # This temporary array is used to read the page title if one single
95 # page to work on is specified by the arguments.
97 # If dry is True, doesn't do any real changes, but only show
98 # what would have been changed.
101 # Parse command line arguments
102 for arg
in pywikibot
.handleArgs():
103 if arg
.startswith("-dry"):
106 # check if a standard argument like
107 # -start:XYZ or -ref:Asdf was given.
108 if not genFactory
.handleArg(arg
):
109 pageTitleParts
.append(arg
)
111 if pageTitleParts
!= []:
112 # We will only work on a single page.
113 pageTitle
= ' '.join(pageTitleParts
)
114 page
= pywikibot
.Page(pywikibot
.getSite(), pageTitle
)
118 gen
= genFactory
.getCombinedGenerator()
120 # The preloading generator is responsible for downloading multiple
121 # pages from the wiki simultaneously.
122 gen
= pagegenerators
.PreloadingGenerator(gen
)
123 bot
= BasicBot(gen
, dry
)
128 if __name__
== "__main__":