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
30 # This is required for the text that is shown when you run this script
31 # with the parameter -help.
33 '¶ms;': pagegenerators
.parameterHelp
37 # Edit summary message that should be used.
38 # NOTE: Put a good description here, and add translations, if possible!
40 'en': u
'Robot correcting misplaced [[WP:WPAFC|AFC]] submission',
43 def __init__(self
, generator
, dry
):
45 Constructor. Parameters:
46 * generator - The page generator that determines on which pages
48 * dry - If True, doesn't do any real changes, but only shows
49 what would have been changed.
51 self
.generator
= generator
54 # Set the edit summary message
55 self
.summary
= pywikibot
.translate(pywikibot
.getSite(), self
.msg
)
59 Loads the given page, does some changes, and saves it.
64 except pywikibot
.NoPage
:
65 pywikibot
.output(u
"Page %s does not exist; skipping."
67 except pywikibot
.IsRedirectPage
:
68 pywikibot
.output(u
"Page %s is a redirect; tagging."
70 page
.put(u
'{{db-g6}}', comment
= "Robot tagging for G6")
76 for page
in self
.generator
:
79 def treat(self
, page
):
81 # Checking for speedies
82 pgtext
= self
.load(page
)
84 wiki_e
= re
.search("{{db-", pgtext
)
88 pywikibot
.output(u
'Page %s not saved, has tag.' % page
.aslink())
89 except AttributeError:
91 if page
.namespace() == 0:
93 #tmp = page.titleWithoutNamespace()
94 #tmp = tmp.replace(tmp.split("/")[0]+"/","")
96 tmp
= "Wikipedia talk:Articles for creation/" + tg
97 if page
.title() == "Wikipedia:Files for upload":
101 if page
.title() == "Wikipedia:Articles for creation/Redirects":
103 self
.doNotMove
= True
105 self
.dry
= self
.perdry
106 self
.doNotMove
= False
112 if not self
.doNotMove
:
113 print "I would have moved " + tg
+ " to: " + tmp
115 if page
.title() == "Wikipedia:Files for upload":
117 if page
.title() == "Wikipedia:Articles for creation/Redirects":
119 print "Moving " + page
.aslink() + " to " + tmp
120 pg2
= pywikibot
.Page(pywikibot
.getSite(), page
.title())
121 page
.move(tmp
, self
.summary
, throttle
=True)
122 pg2
.put(u
'{{db-r2}}', comment
= "Robot tagging for R2")
125 # This factory is responsible for processing command line arguments
126 # that are also used by other scripts and that determine on which pages
128 genFactory
= pagegenerators
.GeneratorFactory()
129 # The generator gives the pages that should be worked upon.
131 # This temporary array is used to read the page title if one single
132 # page to work on is specified by the arguments.
134 # If dry is True, doesn't do any real changes, but only show
135 # what would have been changed.
138 # Parse command line arguments
139 for arg
in pywikibot
.handleArgs():
140 if arg
.startswith("-dry"):
143 # check if a standard argument like
144 # -start:XYZ or -ref:Asdf was given.
145 if not genFactory
.handleArg(arg
):
146 pageTitleParts
.append(arg
)
148 if pageTitleParts
!= []:
149 # We will only work on a single page.
150 pageTitle
= ' '.join(pageTitleParts
)
151 page
= pywikibot
.Page(pywikibot
.getSite(), pageTitle
)
155 gen
= genFactory
.getCombinedGenerator()
157 # The preloading generator is responsible for downloading multiple
158 # pages from the wiki simultaneously.
159 gen
= pagegenerators
.PreloadingGenerator(gen
)
160 bot
= BasicBot(gen
, dry
)
165 if __name__
== "__main__":