daily pastebin goal
33%
SHARE
TWEET

mobiusclock

a guest May 8th, 2010 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2. # -*- coding: utf-8  -*-
  3. # Wikipedia:Bots/Requests_for_approval/Mobius_Bot_2
  4. # Specific CfD replace for settlement categories
  5.  
  6. import wikipedia
  7. import re
  8. import pagegenerators
  9. import catlib
  10.  
  11. from optparse import OptionParser
  12. parser = OptionParser()
  13. parser.add_option("-d", action="store_true", dest="debugmode", default = False)
  14. (options, args) = parser.parse_args()
  15. #Set main site object
  16. site = wikipedia.getSite()
  17. def main():
  18.         R = re.compile(ur'(|Fictional[ ]|former[ ])(|port[ ])(?:cities(?:[,] towns and villages|[ ]and towns|)|(|coastal )settlements|)(|[ ]established) (in|on|of) (.*?)$', re.I) #Compile outside loop for efficiency
  19.         if options.debugmode:
  20.                 wikipedia.output('\03{purple}Debug mode activated: no changes will be made\03{default}') #Display a message if debug mode is on
  21.         for page in pagegenerators.TextfilePageGenerator(): #Will prompt for filename, easier to split into batches
  22.                 if (page.exists()):
  23.                         oldtext = page.get()
  24.                 else:
  25.                         oldtext = ''
  26.                 if ((not page.exists()) or (page.get().find('Cfr full') == -1)):
  27.                         text = u'{{subst:Cfr|'
  28.                         try:
  29.                                 text += R.sub(ur'\1Populated \3 \2places\4 \5 \6', page.title()).replace(' Popul', ' popul').replace('  ', ' ').replace('Port places', 'ports')
  30.                         except:
  31.                                 text += R.sub(ur'\1Populated \2places\4 \5 \6', page.title()).replace(' Popul', ' popul').replace('Port places', 'ports')
  32.                         text += u'|More settlements}}\r\n'
  33.                         #Only actually save the page if the debug flag is NOT set
  34.                         if not options.debugmode:
  35.                                 page.put(text + oldtext, 'Bot: Test')
  36.                         #Else output the diff to the command line
  37.                         else:
  38.                                 wikipedia.output('\03{lightgreen}' + page.title() + '\03{default} \n')
  39.                                 wikipedia.showDiff(oldtext, text + oldtext)
  40.  
  41. if __name__ == '__main__':
  42.     try:
  43.         main()
  44.     finally:
  45.         wikipedia.stopme()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top