Revision: 6377 Author: multichill Date: 2009-02-19 13:18:36 +0000 (Thu, 19 Feb 2009)
Log Message: ----------- Fix author field in information template
Modified Paths: -------------- trunk/pywikipedia/imagecopy.py
Modified: trunk/pywikipedia/imagecopy.py =================================================================== --- trunk/pywikipedia/imagecopy.py 2009-02-19 11:49:11 UTC (rev 6376) +++ trunk/pywikipedia/imagecopy.py 2009-02-19 13:18:36 UTC (rev 6377) @@ -266,12 +266,12 @@ tablock=CH.split('<textarea ')[1].split('>')[0] CH=CH.split('<textarea '+tablock+'>')[1].split('</textarea>')[0] CH=CH.replace(u'×', u'×') - wikipedia.output(CH); - #CH=CH.decode('utf-8') - ## if not '[[category:' in CH.lower(): + CH = self.fixAuthor(CH) + wikipedia.output(CH); + # I want every picture to be tagged with the bottemplate so i can check my contributions later. CH=u'\n\n{{BotMoveToCommons|'+ self.imagePage.site().language() + '.' + self.imagePage.site().family.name +'}}'+CH - #urlEncoding='utf-8' + bot = UploadRobot(url=self.imagePage.fileUrl(), description=CH, useFilename=self.newname, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = wikipedia.getSite('commons', 'commons')) bot.run()
@@ -311,7 +311,29 @@ imagebot = ImageRobot(generator = self.preloadingGen, oldImage = self.imagePage.titleWithoutNamespace(), newImage = self.newname, summary = moveSummary, always = True, loose = True) imagebot.run() return + + def fixAuthor(self, pageText): + ''' + Fix the author field in the information template. + ''' + informationRegex = re.compile(u'|Author=Original uploader was (?P<author>[[:\w+:\w+:\w+|\w+]] at [.+])') + selfRegex = re.compile(u'{{self|author=(?P<author>[[:\w+:\w+:\w+|\w+]] at [.+])|')
+ #Find the |Author=Original uploader was .... + informationMatch = informationRegex.search(pageText) + + #Find the {{self|author= + selfMatch = selfRegex.search(pageText) + + #Check if both are found and are equal + if (informationMatch and selfMatch): + if(informationMatch.group('author')==selfMatch.group('author')): + #Replace |Author=Original uploader was ... with |Author= ... + pageText = informationRegex.sub(r'|Author=\g<author>', pageText) + + return pageText + + #-label ok skip view #textarea archivo=wikipedia.config.datafilepath("Uploadbot.localskips.txt")