jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/480076 )
Change subject: [IMPR] Use SingleSiteBot with states_redirect.py ......................................................................
[IMPR] Use SingleSiteBot with states_redirect.py
Bot class is noted as to be deprecated. Use SingleSitesBot instead.
- StatesRedirectBot.site is set by super class but the generator must become an StatesRedirectBot property - Create the abbrev in setup method
Change-Id: Ic061ee0d8f92033c7ec1086b26f9d1dca806f2ba --- M scripts/states_redirect.py 1 file changed, 15 insertions(+), 12 deletions(-)
Approvals: D3r1ck01: Looks good to me, but someone else must approve Framawiki: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/states_redirect.py b/scripts/states_redirect.py index 10802b7..18829e2 100755 --- a/scripts/states_redirect.py +++ b/scripts/states_redirect.py @@ -25,7 +25,7 @@
import pywikibot
-from pywikibot.bot import suggest_help +from pywikibot.bot import SingleSiteBot, suggest_help from pywikibot import i18n
try: @@ -34,32 +34,35 @@ pycountry = e
-class StatesRedirectBot(pywikibot.Bot): +class StatesRedirectBot(SingleSiteBot):
"""Bot class used for implementation of re-direction norms."""
def __init__(self, start, force): """Initializer.
- Parameters: - @param start:xxx Specify the place in the alphabet to start - searching. - @param force: Don't ask whether to create pages, just create - them. + @param start:xxx Specify the place in the alphabet to start searching. + @type start: str + @param force: Don't ask whether to create pages, just create them. + @type force: bool """ - site = pywikibot.Site() - generator = site.allpages(start=start) - super(StatesRedirectBot, self).__init__(generator=generator) - + super(StatesRedirectBot, self).__init__() + self.start = start self.force = force
- # Created abbrev from pycountry data base + def setup(self): + """Create abbrev from pycountry data base.""" self.abbrev = {} for subd in pycountry.subdivisions: # Used subd.code[3:] to extract the exact code for # subdivisional states(ignoring the country code). self.abbrev[subd.name] = subd.code[3:]
+ @property + def generator(self): + """Generator used by run() method.""" + return self.site.allpages(start=self.start) + def treat(self, page): """Re-directing process.