Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wikipedia
- from wikipedia import pywikibot
- # Define the main function
- def main():
- for arg in pywikibot.handleArgs():
- if arg.startswith('-page'):
- number = arg.split(':',1)
- site = wikipedia.getSite('en','wikipedia')
- pagename = (u'User:RileyBot/Stop/%s' % number)
- page = wikipedia.Page(site, pagename)
- wikipedia.output(u"Loading %s..." % pagename) # Please, see the "u" before the text
- try:
- text = page.get()
- except wikipedia.IsRedirectPage: # second except, prevent redirect
- wikipedia.output(u'%s is a redirect!' % pagename)
- exit()# wikipedia.stopme() is in the finally, we don't need to use it twice, exit() will only close the script
- except wikipedia.Error: # third exception, take the problem and print
- wikipedia.output(u"Some Error, skipping..")
- exit()
- newtext = 'enable'
- page.put(newtext, comment='[[User:RileyBot|Bot]]: Enabling [[User:RileyBot/14|Task 14]] as requested by bot operator') # page.put(newtext, 'Bot: Test')
- if __name__ == '__main__':
- try:
- main()
- finally:
- wikipedia.stopme()
Advertisement
Add Comment
Please, Sign In to add comment