User:Paddy/changeLogo.pl

From Wikimedia Commons, the free media repository
Jump to: navigation, search
#!/usr/bin/python
# -*- coding: UTF-8 -*-;

import re
import string
import sys
import difflib

inFile = open("/home/user/path/Filename", "r")
T = inFile.read()
Template=unicode(T, 'utf-8')
inFile.close()

KRegion = re.compile( u'Image:Wikinews-trans_135px_ohne_text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikinews-logo.png', Template)
KRegion = re.compile( u'Image:Wikinews-trans 135px ohne text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikinews-logo.png', wikinew)

KRegion = re.compile( u'Image:Commons_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Commons-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Commons without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Commons-logo.png|35px', wikinew)

KRegion = re.compile( u'Image:Wikimedia_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikimedia-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikimedia without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikimedia-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikipedia_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikipedia-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikipedia without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikipedia-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wiktionary-logo-en-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wiktionary-logo-en.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikibooks_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikibooks-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikibooks without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikibooks-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikiquote_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikiquote-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikiquote without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikiquote-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikispecies_without_text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png', wikinew)
KRegion = re.compile( u'Image:Wikispecies without text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png', wikinew)
                                
KRegion = re.compile( u'Image:Wikispecies_without_text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikispecies without text-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikispecies-trans 135px ohne text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Wikispecies-trans 135px ohne text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikispecies-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Meta-trans 135px ohne text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikimedia-logo.png|35px', wikinew)
KRegion = re.compile( u'Image:Meta-trans 135px ohne text.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikimedia-logo.png|35px', wikinew)
                                
KRegion = re.compile( u'Image:Wikinews-logo2-35px.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikinews-logo.png|35px', wikinew)

KRegion = re.compile( u'Image:Wikisource-logo-35px.jpg', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikisource-logo.png|35px', wikinew)
#
KRegion = re.compile( u' without text', re.IGNORECASE)
wikinew = KRegion.sub( u'-logo.png|35px', wikinew)

KRegion = re.compile( u'logo2', re.IGNORECASE)
wikinew = KRegion.sub( u'logo|35px', wikinew)

KRegion = re.compile( u'Image:Wikinews-logo.png', re.IGNORECASE)
wikinew = KRegion.sub( u'Image:Wikinews-logo-en.png|35px', wikinew)

                                
KRegion = re.compile( u'\|35px\|35px', re.IGNORECASE)
wikinew = KRegion.sub( u'|35px', wikinew)

if Template == wikinew:
        print "no changes needed"
else:
        #print "writing page!"
        '''
        surplusBlanks = re.compile( r'(?m) +\n',re.MULTILINE)
        compare = surplusBlanks.sub( r'\n', Template)
        for line in difflib.ndiff(compare.split('\n'),wikinew.split('\n')):
                if line[0] in ['+','-']:
                        print unicode(repr(line)[2:-1])
        '''
        
        print wikinew.encode('utf-8')
sys.exit(0)