Riley_Huntley

Untitled

Apr 22nd, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import wikipedia
  2. from wikipedia import pywikibot
  3. # Define the main function
  4. def main():
  5. for arg in pywikibot.handleArgs():
  6. if arg.startswith('-page'):
  7. number = arg.split(':',1)
  8. site = wikipedia.getSite('en','wikipedia')
  9. pagename = (u'User:RileyBot/Stop/%s' % number)
  10. page = wikipedia.Page(site, pagename)
  11. wikipedia.output(u"Loading %s..." % pagename) # Please, see the "u" before the text
  12. try:
  13. text = page.get()
  14. except wikipedia.IsRedirectPage: # second except, prevent redirect
  15. wikipedia.output(u'%s is a redirect!' % pagename)
  16. exit()# wikipedia.stopme() is in the finally, we don't need to use it twice, exit() will only close the script
  17. except wikipedia.Error: # third exception, take the problem and print
  18. wikipedia.output(u"Some Error, skipping..")
  19. exit()
  20. newtext = 'enable'
  21. page.put(newtext, comment='[[User:RileyBot|Bot]]: Enabling [[User:RileyBot/14|Task 14]] as requested by bot operator') # page.put(newtext, 'Bot: Test')
  22.  
  23. if __name__ == '__main__':
  24. try:
  25. main()
  26. finally:
  27. wikipedia.stopme()
Advertisement
Add Comment
Please, Sign In to add comment