Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # Wikipedia:Bots/Requests_for_approval/Mobius_Bot_2
- # Specific CfD replace for settlement categories
- import wikipedia
- import re
- import pagegenerators
- import catlib
- from optparse import OptionParser
- parser = OptionParser()
- parser.add_option("-d", action="store_true", dest="debugmode", default = False)
- (options, args) = parser.parse_args()
- #Set main site object
- site = wikipedia.getSite()
- def main():
- 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
- if options.debugmode:
- wikipedia.output('\03{purple}Debug mode activated: no changes will be made\03{default}') #Display a message if debug mode is on
- for page in pagegenerators.TextfilePageGenerator(): #Will prompt for filename, easier to split into batches
- if (page.exists()):
- oldtext = page.get()
- else:
- oldtext = ''
- if ((not page.exists()) or (page.get().find('Cfr full') == -1)):
- text = u'{{subst:Cfr|'
- try:
- text += R.sub(ur'\1Populated \3 \2places\4 \5 \6', page.title()).replace(' Popul', ' popul').replace(' ', ' ').replace('Port places', 'ports')
- except:
- text += R.sub(ur'\1Populated \2places\4 \5 \6', page.title()).replace(' Popul', ' popul').replace('Port places', 'ports')
- text += u'|More settlements}}\r\n'
- #Only actually save the page if the debug flag is NOT set
- if not options.debugmode:
- page.put(text + oldtext, 'Bot: Test')
- #Else output the diff to the command line
- else:
- wikipedia.output('\03{lightgreen}' + page.title() + '\03{default} \n')
- wikipedia.showDiff(oldtext, text + oldtext)
- if __name__ == '__main__':
- try:
- main()
- finally:
- wikipedia.stopme()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement