Revision: 8526 Author: xqt Date: 2010-09-11 16:45:50 +0000 (Sat, 11 Sep 2010)
Log Message: ----------- import wikipedia as pywikibot for merging to rewrite branch
Modified Paths: -------------- trunk/pywikipedia/imagecopy.py trunk/pywikipedia/imagecopy_enwp.py trunk/pywikipedia/imagecopy_self.py
Modified: trunk/pywikipedia/imagecopy.py =================================================================== --- trunk/pywikipedia/imagecopy.py 2010-09-11 16:21:58 UTC (rev 8525) +++ trunk/pywikipedia/imagecopy.py 2010-09-11 16:45:50 UTC (rev 8526) @@ -72,11 +72,13 @@ # (C) Wikipedian, Keichwa, Leogregianin, Rikwade, Misza13 2003-2007 # # New bot by: -# (C) Kyle/Orgullomoore, Siebrand Mazeland 2007 +# (C) Kyle/Orgullomoore, Siebrand Mazeland 2007-2008 # # Another rewrite by: -# (C) Multichill 2008 +# (C) Multichill 2008-2010 # +# (C) Pywikipedia bot team, 2003-2010 +# # Distributed under the terms of the MIT license. # __version__='$Id$' @@ -87,7 +89,8 @@ import urllib, httplib, urllib2 import webbrowser import time, threading -import wikipedia, config, socket +import wikipedia as pywikibot +import config, socket import pagegenerators, add_text from upload import * from image import * @@ -242,9 +245,9 @@ data = commonsHelperPage.read().decode('utf-8') gotInfo = True; except IOError: - wikipedia.output(u'Got an IOError, let's try again') + pywikibot.output(u'Got an IOError, let's try again') except socket.timeout: - wikipedia.output(u'Got a timeout, let's try again') + pywikibot.output(u'Got a timeout, let's try again') return data
class imageTransfer (threading.Thread): @@ -276,7 +279,7 @@ CH=CH.split('<textarea '+tablock+'>')[1].split('</textarea>')[0] CH=CH.replace(u'×', u'×') CH = self.fixAuthor(CH) - wikipedia.output(CH); + pywikibot.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 +'|year={{subst:CURRENTYEAR}}|month={{subst:CURRENTMONTHNAME}}|day={{subst:CURRENTDAY}}}}' + CH @@ -285,11 +288,11 @@ CH = CH.replace(u'{{subst:Unc}} <!-- Remove this line once you have added categories -->', u'') CH = CH + u'[[Category:' + self.category + u']]'
- bot = UploadRobot(url=self.imagePage.fileUrl(), description=CH, useFilename=self.newname, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = wikipedia.getSite('commons', 'commons')) + bot = UploadRobot(url=self.imagePage.fileUrl(), description=CH, useFilename=self.newname, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = pywikibot.getSite('commons', 'commons')) bot.run()
#Should check if the image actually was uploaded - if wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'Image:' + self.newname).exists(): + if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'Image:' + self.newname).exists(): #Get a fresh copy, force to get the page so we dont run into edit conflicts imtxt=self.imagePage.get(force=True)
@@ -309,7 +312,7 @@ else: commentText = nowCommonsMessage['_default']
- wikipedia.showDiff(self.imagePage.get(), imtxt+addTemplate) + pywikibot.showDiff(self.imagePage.get(), imtxt+addTemplate) self.imagePage.put(imtxt + addTemplate, comment = commentText)
self.gen = pagegenerators.FileLinksGenerator(self.imagePage) @@ -349,7 +352,7 @@
#-label ok skip view #textarea -archivo=wikipedia.config.datafilepath("Uploadbot.localskips.txt") +archivo=pywikibot.config.datafilepath("Uploadbot.localskips.txt") try: open(archivo, 'r') except IOError: @@ -476,7 +479,7 @@ # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory()
- for arg in wikipedia.handleArgs(): + for arg in pywikibot.handleArgs(): if arg == '-always': always = True elif arg.startswith('-cc:'): @@ -493,11 +496,11 @@ for page in pregenerator: skip = False if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()) : - imagepage = wikipedia.ImagePage(page.site(), page.title()) + imagepage = pywikibot.ImagePage(page.site(), page.title())
#First do autoskip. if doiskip(imagepage.get()): - wikipedia.output("Skipping " + page.title()) + pywikibot.output("Skipping " + page.title()) skip = True else: # The first upload is last in the list. @@ -508,7 +511,7 @@ (datetime, username, resolution, size, comment) = imagepage.getFileVersionHistory().pop() if always: newname=imagepage.titleWithoutNamespace() - CommonsPage=wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'File:'+newname) + CommonsPage=pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:'+newname) if CommonsPage.exists(): skip = True else: @@ -518,7 +521,7 @@ (newname, skip)=Tkdialog(imagepage.titleWithoutNamespace(), imagepage.get(), username, imagepage.permalink(), imagepage.templates()).getnewname()
if skip: - wikipedia.output('Skipping this image') + pywikibot.output('Skipping this image') break
# Did we enter a new name? @@ -529,26 +532,26 @@ newname = newname.decode('utf-8')
# Check if the image already exists - CommonsPage=wikipedia.Page( - wikipedia.getSite('commons', 'commons'), + CommonsPage=pywikibot.Page( + pywikibot.getSite('commons', 'commons'), u'File:'+newname) if not CommonsPage.exists(): break else: - wikipedia.output('Image already exists, pick another name or skip this image') + pywikibot.output('Image already exists, pick another name or skip this image') # We dont overwrite images, pick another name, go to the start of the loop
if not skip: imageTransfer(imagepage, newname, category).start()
- wikipedia.output(u'Still ' + str(threading.activeCount()) + u' active threads, lets wait') + pywikibot.output(u'Still ' + str(threading.activeCount()) + u' active threads, lets wait') for openthread in threading.enumerate(): if openthread != threading.currentThread(): openthread.join() - wikipedia.output(u'All threads are done') + pywikibot.output(u'All threads are done')
if __name__ == "__main__": try: main(sys.argv[1:]) finally: - wikipedia.stopme() + pywikibot.stopme()
Modified: trunk/pywikipedia/imagecopy_enwp.py =================================================================== --- trunk/pywikipedia/imagecopy_enwp.py 2010-09-11 16:21:58 UTC (rev 8525) +++ trunk/pywikipedia/imagecopy_enwp.py 2010-09-11 16:45:50 UTC (rev 8526) @@ -42,6 +42,8 @@ # English Wikipedia specific bot by: # (C) Multichill 2010 # +# (C) Pywikipedia bot team, 2003-2010 +# # Distributed under the terms of the MIT license. # __version__='$Id$' @@ -53,7 +55,8 @@ import webbrowser from Queue import Queue import time, threading -import wikipedia, config, socket +import wikipedia as pywikibot +import config, socket import pagegenerators, add_text import imagerecat from datetime import datetime @@ -127,7 +130,8 @@ ]
class Tkdialog: - def __init__(self, imagepage, description, date, source, author, licensetemplate, categories): + def __init__(self, imagepage, description, date, source, author, + licensetemplate, categories): self.root=Tk() #"%dx%d%+d%+d" % (width, height, xoffset, yoffset) #Always appear the same size and in the bottom-left corner @@ -140,7 +144,9 @@
self.old_description=Text(self.root) self.old_description.insert(END, imagepage.get().encode('utf-8')) - self.old_description.config(state=DISABLED, height=8, width=140, padx=0, pady=0, wrap=WORD, yscrollcommand=self.scrollbar.set) + self.old_description.config(state=DISABLED, height=8, width=140, padx=0, + pady=0, wrap=WORD, + yscrollcommand=self.scrollbar.set)
self.scrollbar.config(command=self.old_description.yview)
@@ -154,23 +160,28 @@ self.categories = categories self.skip = False
- self.old_description_label=Label(self.root,text=u'The old description was : ') - self.new_description_label=Label(self.root,text=u'The new fields are : ') - self.filename_label=Label(self.root,text=u'Filename : ') - self.information_description_label=Label(self.root,text=u'Description : ') - self.information_date_label=Label(self.root,text=u'Date : ') - self.information_source_label=Label(self.root,text=u'Source : ') - self.information_author_label=Label(self.root,text=u'Author : ') - self.information_licensetemplate_label=Label(self.root,text=u'License : ') - self.information_categories_label=Label(self.root,text=u'Categories : ') + self.old_description_label = Label(self.root, + text=u'The old description was : ') + self.new_description_label = Label(self.root, + text=u'The new fields are : ') + self.filename_label = Label(self.root, text=u'Filename : ') + self.information_description_label = Label(self.root, + text=u'Description : ') + self.information_date_label = Label(self.root, text=u'Date : ') + self.information_source_label = Label(self.root, text=u'Source : ') + self.information_author_label = Label(self.root, text=u'Author : ') + self.information_licensetemplate_label = Label(self.root, + text=u'License : ') + self.information_categories_label = Label(self.root, + text=u'Categories : ')
- self.filename_field=Entry(self.root) - self.information_description=Entry(self.root) - self.information_date=Entry(self.root) - self.information_source=Entry(self.root) - self.information_author=Entry(self.root) - self.information_licensetemplate=Entry(self.root) - self.information_categories=Entry(self.root) + self.filename_field = Entry(self.root) + self.information_description = Entry(self.root) + self.information_date = Entry(self.root) + self.information_source = Entry(self.root) + self.information_author = Entry(self.root) + self.information_licensetemplate = Entry(self.root) + self.information_categories = Entry(self.root)
self.field_width=120
@@ -282,7 +293,7 @@ for page in self.pagegenerator: self.processImage(page) self.prefetchQueue.put(None) - wikipedia.output(u'Fetched all images.') + pywikibot.output(u'Fetched all images.') return True
def processImage(self, page): @@ -290,11 +301,11 @@ Work on a single image ''' if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()): - imagepage = wikipedia.ImagePage(page.site(), page.title()) + imagepage = pywikibot.ImagePage(page.site(), page.title())
#First do autoskip. if self.doiskip(imagepage): - wikipedia.output(u'Skipping %s : Got a template on the skip list.' % page.title()) + pywikibot.output(u'Skipping %s : Got a template on the skip list.' % page.title()) return False
text = imagepage.get() @@ -304,7 +315,7 @@ if match: foundMatch = True if not foundMatch: - wikipedia.output(u'Skipping %s : No suitable license template was found.' % page.title()) + pywikibot.output(u'Skipping %s : No suitable license template was found.' % page.title()) return False self.prefetchQueue.put(self.getNewFields(imagepage))
@@ -315,7 +326,7 @@ ''' for template in imagepage.templates(): if template in skipTemplates: - wikipedia.output(u'Found ' + template + u' which is on the template skip list') + pywikibot.output(u'Found ' + template + u' which is on the template skip list') return True return False
@@ -333,9 +344,10 @@ return (imagepage, description, date, source, author, licensetemplate, categories)
def getNewFieldsFromInformation(self, imagepage): + ''' Try to extract fields from the current information template for the + newinformation template. + ''' - Try to extract fields from the current information template for the new information template. - ''' description = u'' date = u'' source = u'' @@ -352,22 +364,29 @@ for regex in regexes: match =re.search(regex, text, re.IGNORECASE|re.DOTALL) if match: - description = self.convertLinks(match.group(u'description').strip(), imagepage.site()) + description = self.convertLinks( + match.group(u'description').strip(), imagepage.site())
date = match.group(u'date').strip() if date == u'': date = self.getUploadDate(imagepage)
- source = self.getSource(imagepage, source=self.convertLinks(match.group(u'source').strip(), imagepage.site())) + source = self.getSource(imagepage, + source=self.convertLinks( + match.group(u'source').strip(), + imagepage.site()))
- author = self.convertLinks(match.group(u'author').strip(), imagepage.site()) + author = self.convertLinks(match.group(u'author').strip(), + imagepage.site()) if author == u'': author = self.getAuthorText(imagepage)
if u'permission' in match.groupdict(): - permission = self.convertLinks(match.group(u'permission').strip(), imagepage.site()) + permission = self.convertLinks( + match.group(u'permission').strip(), imagepage.site()) if u'other_versions' in match.groupdict(): - other_versions = self.convertLinks(match.group(u'other_versions').strip(), imagepage.site()) + other_versions = self.convertLinks( + match.group(u'other_versions').strip(), imagepage.site()) # Return the stuff we found return (description, date, source, author)
@@ -389,7 +408,7 @@ for (regex, repl) in licenseTemplates: text = re.sub(regex, u'', text, re.IGNORECASE)
- text = wikipedia.removeCategoryLinks(text, imagepage.site()).strip() + text = pywikibot.removeCategoryLinks(text, imagepage.site()).strip()
description = self.convertLinks(text.strip(), imagepage.site()) date = self.getUploadDate(imagepage) @@ -398,9 +417,10 @@ return (description, date, source, author)
def getUploadDate(self, imagepage): + ''' Get the original upload date to put in the date field of the new + information template. If we really have nothing better. + ''' - Get the original upload date to put in the date field of the new information template. If we really have nothing better. - ''' uploadtime = imagepage.getFileVersionHistory()[-1][0] uploadDatetime = datetime.strptime(uploadtime, u'%Y-%m-%dT%H:%M:%SZ') return u'{{Date|' + str(uploadDatetime.year) + u'|' + str(uploadDatetime.month) + u'|' + str(uploadDatetime.day) + u'}} (original upload date)' @@ -414,19 +434,23 @@ family = site.family.name if source==u'': source=u'{{Own}}' - - return source.strip() + u'<BR />Transferred from [http://%(lang)s.%(family)s.org %(lang)s.%(family)s]' % {u'lang' : lang, u'family' : family} + return source.strip() + \ + u'<BR />Transferred from [http://%(lang)s.%(family)s.org %(lang)s.%(family)s]' \ + % {u'lang' : lang, u'family' : family}
def getAuthorText(self, imagepage): + ''' Get the original uploader to put in the author field of the new + information template. + ''' - Get the original uploader to put in the author field of the new information template. - ''' site = imagepage.site() lang = site.language() family = site.family.name
firstuploader = self.getAuthor(imagepage) - return u'[[:%(lang)s:User:%(firstuploader)s|%(firstuploader)s]] at [http://%(lang)s.%(family)s.org %(lang)s.%(family)s]' % {u'lang' : lang, u'family' : family , u'firstuploader' : firstuploader} + return u'[[:%(lang)s:User:%(firstuploader)s|%(firstuploader)s]] at [http://%(lang)s.%(family)s.org %(lang)s.%(family)s]' \ + % {u'lang' : lang, u'family' : family , + u'firstuploader' : firstuploader}
def getAuthor(self, imagepage): ''' @@ -440,13 +464,14 @@ ''' lang = sourceSite.language() family = sourceSite.family.name - conversions =[(u'[[([^[]|]+)|([^[]|]+)]]', u'[[:%(lang)s:\1|\2]]'), + conversions =[(u'[[([^[]|]+)|([^[]|]+)]]', + u'[[:%(lang)s:\1|\2]]'), (u'[[([^[]|]+)]]', u'[[:%(lang)s:\1|\1]]'), ]
for (regex, replacement) in conversions: - text = re.sub(regex, replacement % {u'lang' : lang, u'family' : family}, text) - + text = re.sub(regex, replacement + % {u'lang' : lang, u'family' : family}, text) return text
def getNewLicensetemplate(self, imagepage): @@ -454,21 +479,18 @@ Get a license template to put on the image to be uploaded ''' text = imagepage.get() - site = imagepage.site() lang = site.language() family = site.family.name - result = u'' - for (regex, replacement) in licenseTemplates: match = re.search(regex, text, re.IGNORECASE) if match: - result = re.sub(regex, replacement, match.group(0), re.IGNORECASE) + result = re.sub(regex, replacement, match.group(0), + re.IGNORECASE) return result % {u'author' : self.getAuthor(imagepage), u'lang' : lang, u'family' : family} - return result
def getNewCategories(self, imagepage): @@ -477,10 +499,11 @@ Dont forget to filter ''' result = u'' - (commonshelperCats, usage, galleries) = imagerecat.getCommonshelperCats(imagepage) + (commonshelperCats, usage, galleries) = \ + imagerecat.getCommonshelperCats(imagepage) newcats = imagerecat.applyAllFilters(commonshelperCats) for newcat in newcats: - result = result + u'[[Category:' + newcat + u']] ' + result += u'[[Category:' + newcat + u']] ' return result
class userInteraction(threading.Thread): @@ -500,28 +523,32 @@ else: break self.uploadQueue.put(None) - wikipedia.output(u'User worked on all images.') + pywikibot.output(u'User worked on all images.') return True
def processImage(self, fields): ''' Work on a single image ''' - (imagepage, description, date, source, author, licensetemplate, categories) = fields + (imagepage, description, date, source, author, licensetemplate, + categories) = fields while True: # Do the Tkdialog to accept/reject and change te name - (filename, description, date, source, author, licensetemplate, categories, skip)=Tkdialog(imagepage, description, date, source, author, licensetemplate, categories).getnewmetadata() + (filename, description, date, source, author, licensetemplate, + categories, skip) = Tkdialog(imagepage, description, date, source, + author, licensetemplate, categories).getnewmetadata()
if skip: - wikipedia.output(u'Skipping %s : User pressed skip.' % imagepage.title()) + pywikibot.output(u'Skipping %s : User pressed skip.' + % imagepage.title()) return False
# Check if the image already exists - CommonsPage=wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'File:' + filename) + CommonsPage = pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename) if not CommonsPage.exists(): break else: - wikipedia.output('Image already exists, pick another name or skip this image') + pywikibot.output('Image already exists, pick another name or skip this image') # We dont overwrite images, pick another name, go to the start of the loop
self.uploadQueue.put((imagepage, filename, description, date, source, author, licensetemplate, categories)) @@ -558,8 +585,8 @@ ''' (imagepage, filename, description, date, source, author, licensetemplate, categories) = fields cid = self.buildNewImageDescription(imagepage, description, date, source, author, licensetemplate, categories) - wikipedia.output(cid) - bot = UploadRobot(url=imagepage.fileUrl(), description=cid, useFilename=filename, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = wikipedia.getSite('commons', 'commons')) + pywikibot.output(cid) + bot = UploadRobot(url=imagepage.fileUrl(), description=cid, useFilename=filename, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = pywikibot.getSite('commons', 'commons')) bot.run()
self.tagNowcommons(imagepage, filename) @@ -631,7 +658,7 @@ ''' Tagged the imag which has been moved to Commons for deletion. ''' - if wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'File:' + filename).exists(): + if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists(): #Get a fresh copy, force to get the page so we dont run into edit conflicts imtxt=imagepage.get(force=True)
@@ -651,7 +678,7 @@ else: commentText = nowCommonsMessage['_default']
- wikipedia.showDiff(imagepage.get(), imtxt + addTemplate) + pywikibot.showDiff(imagepage.get(), imtxt + addTemplate) imagepage.put(imtxt + addTemplate, comment = commentText)
def replaceUsage(self, imagepage, filename): @@ -671,10 +698,10 @@
def main(args): - wikipedia.output(u'WARNING: This is an experimental bot') - wikipedia.output(u'WARNING: It will only work on self published work images') - wikipedia.output(u'WARNING: This bot is still full of bugs') - wikipedia.output(u'WARNING: Use at your own risk!') + pywikibot.output(u'WARNING: This is an experimental bot') + pywikibot.output(u'WARNING: It will only work on self published work images') + pywikibot.output(u'WARNING: This bot is still full of bugs') + pywikibot.output(u'WARNING: Use at your own risk!')
generator = None; always = False @@ -683,7 +710,7 @@ # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory()
- for arg in wikipedia.handleArgs(): + for arg in pywikibot.handleArgs(): if arg == '-nochecktemplate': checkTemplate = False else: @@ -718,4 +745,4 @@ try: main(sys.argv[1:]) finally: - wikipedia.stopme() + pywikibot.stopme()
Modified: trunk/pywikipedia/imagecopy_self.py =================================================================== --- trunk/pywikipedia/imagecopy_self.py 2010-09-11 16:21:58 UTC (rev 8525) +++ trunk/pywikipedia/imagecopy_self.py 2010-09-11 16:45:50 UTC (rev 8526) @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- """ -Script to copy self published files from the English Wikipedia to Wikimedia Commons. +Script to copy self published files from the English Wikipedia to Wikimedia +Commons.
-This bot is based on imagecopy.py and intended to be used to empty out http://en.wikipedia.org/wiki/Category:Self-published_work +This bot is based on imagecopy.py and intended to be used to empty out +http://en.wikipedia.org/wiki/Category:Self-published_work
This bot uses a graphical interface and may not work from commandline only environment. @@ -21,10 +23,12 @@
This is a first test version and should be used with care.
-Use -nochecktemplate if you don't want to add the check template. Be sure to check it yourself. +Use -nochecktemplate if you don't want to add the check template. Be sure to +check it yourself.
Todo: -*Queues with threads have to be implemented for the information collecting part and for the upload part. +*Queues with threads have to be implemented for the information collecting part + and for the upload part. *Categories are now on a single line. Something like hotcat would be nice.
""" @@ -42,6 +46,8 @@ # English Wikipedia specific bot by: # (C) Multichill 2010 # +# (C) Pywikipedia bot team, 2003-2010 +# # Distributed under the terms of the MIT license. # __version__='$Id$' @@ -53,7 +59,8 @@ import webbrowser from Queue import Queue import time, threading -import wikipedia, config, socket +import wikipedia as pywikibot +import config, socket import pagegenerators, add_text import imagerecat from datetime import datetime @@ -154,23 +161,28 @@ self.categories = categories self.skip = False
- self.old_description_label=Label(self.root,text=u'The old description was : ') - self.new_description_label=Label(self.root,text=u'The new fields are : ') - self.filename_label=Label(self.root,text=u'Filename : ') - self.information_description_label=Label(self.root,text=u'Description : ') - self.information_date_label=Label(self.root,text=u'Date : ') - self.information_source_label=Label(self.root,text=u'Source : ') - self.information_author_label=Label(self.root,text=u'Author : ') - self.information_licensetemplate_label=Label(self.root,text=u'License : ') - self.information_categories_label=Label(self.root,text=u'Categories : ') + self.old_description_label = Label(self.root, + text=u'The old description was : ') + self.new_description_label = Label(self.root, + text=u'The new fields are : ') + self.filename_label = Label(self.root, text=u'Filename : ') + self.information_description_label = Label(self.root, + text=u'Description : ') + self.information_date_label = Label(self.root, text=u'Date : ') + self.information_source_label = Label(self.root, text=u'Source : ') + self.information_author_label = Label(self.root, text=u'Author : ') + self.information_licensetemplate_label = Label(self.root, + text=u'License : ') + self.information_categories_label = Label(self.root, + text=u'Categories : ')
- self.filename_field=Entry(self.root) - self.information_description=Entry(self.root) - self.information_date=Entry(self.root) - self.information_source=Entry(self.root) - self.information_author=Entry(self.root) - self.information_licensetemplate=Entry(self.root) - self.information_categories=Entry(self.root) + self.filename_field = Entry(self.root) + self.information_description = Entry(self.root) + self.information_date = Entry(self.root) + self.information_source = Entry(self.root) + self.information_author = Entry(self.root) + self.information_licensetemplate = Entry(self.root) + self.information_categories = Entry(self.root)
self.field_width=120
@@ -191,7 +203,8 @@ self.information_licensetemplate.insert(0, self.licensetemplate) self.information_categories.insert(0, self.categories)
- self.browserButton=Button(self.root, text='View in browser', command=self.openInBrowser) + self.browserButton=Button(self.root, text='View in browser', + command=self.openInBrowser) self.skipButton=Button(self.root, text="Skip", command=self.skipFile) self.okButton=Button(self.root, text="OK", command=self.okFile)
@@ -265,7 +278,8 @@ Activate the dialog and return the new name and if the image is skipped. ''' self.root.mainloop() - return (self.filename, self.description, self.date, self.source, self.author, self.licensetemplate, self.categories, self.skip) + return (self.filename, self.description, self.date, self.source, + self.author, self.licensetemplate, self.categories, self.skip)
class imageFetcher(threading.Thread): @@ -282,19 +296,22 @@ for page in self.pagegenerator: self.processImage(page) self.prefetchQueue.put(None) - wikipedia.output(u'Fetched all images.') + pywikibot.output(u'Fetched all images.') return True
def processImage(self, page): ''' Work on a single image ''' - if page.exists() and (page.namespace() == 6) and (not page.isRedirectPage()): - imagepage = wikipedia.ImagePage(page.site(), page.title()) + if page.exists() and (page.namespace() == 6) and \ + (not page.isRedirectPage()): + imagepage = pywikibot.ImagePage(page.site(), page.title())
#First do autoskip. if self.doiskip(imagepage): - wikipedia.output(u'Skipping %s : Got a template on the skip list.' % page.title()) + pywikibot.output( + u'Skipping %s : Got a template on the skip list.' + % page.title()) return False
text = imagepage.get() @@ -304,7 +321,9 @@ if match: foundMatch = True if not foundMatch: - wikipedia.output(u'Skipping %s : No suitable license template was found.' % page.title()) + pywikibot.output( + u'Skipping %s : No suitable license template was found.' + % page.title()) return False self.prefetchQueue.put(self.getNewFields(imagepage))
@@ -315,7 +334,8 @@ ''' for template in imagepage.templates(): if template in skipTemplates: - wikipedia.output(u'Found ' + template + u' which is on the template skip list') + pywikibot.output( + u'Found %s which is on the template skip list' % template) return True return False
@@ -345,7 +365,6 @@ author = u'' permission = u'' other_versions = u'' - contents = {}
for field in fields: @@ -414,7 +433,7 @@ for (regex, repl) in licenseTemplates: text = re.sub(regex, u'', text, re.IGNORECASE)
- text = wikipedia.removeCategoryLinks(text, imagepage.site()).strip() + text = pywikibot.removeCategoryLinks(text, imagepage.site()).strip()
description = self.convertLinks(text.strip(), imagepage.site()) date = self.getUploadDate(imagepage) @@ -525,7 +544,7 @@ else: break self.uploadQueue.put(None) - wikipedia.output(u'User worked on all images.') + pywikibot.output(u'User worked on all images.') return True
def processImage(self, fields): @@ -538,15 +557,15 @@ (filename, description, date, source, author, licensetemplate, categories, skip)=Tkdialog(imagepage, description, date, source, author, licensetemplate, categories).getnewmetadata()
if skip: - wikipedia.output(u'Skipping %s : User pressed skip.' % imagepage.title()) + pywikibot.output(u'Skipping %s : User pressed skip.' % imagepage.title()) return False
# Check if the image already exists - CommonsPage=wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'File:' + filename) + CommonsPage=pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename) if not CommonsPage.exists(): break else: - wikipedia.output('Image already exists, pick another name or skip this image') + pywikibot.output('Image already exists, pick another name or skip this image') # We dont overwrite images, pick another name, go to the start of the loop
self.uploadQueue.put((imagepage, filename, description, date, source, author, licensetemplate, categories)) @@ -583,8 +602,8 @@ ''' (imagepage, filename, description, date, source, author, licensetemplate, categories) = fields cid = self.buildNewImageDescription(imagepage, description, date, source, author, licensetemplate, categories) - wikipedia.output(cid) - bot = UploadRobot(url=imagepage.fileUrl(), description=cid, useFilename=filename, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = wikipedia.getSite('commons', 'commons')) + pywikibot.output(cid) + bot = UploadRobot(url=imagepage.fileUrl(), description=cid, useFilename=filename, keepFilename=True, verifyDescription=False, ignoreWarning = True, targetSite = pywikibot.getSite('commons', 'commons')) bot.run()
self.tagNowcommons(imagepage, filename) @@ -656,7 +675,7 @@ ''' Tagged the imag which has been moved to Commons for deletion. ''' - if wikipedia.Page(wikipedia.getSite('commons', 'commons'), u'File:' + filename).exists(): + if pywikibot.Page(pywikibot.getSite('commons', 'commons'), u'File:' + filename).exists(): #Get a fresh copy, force to get the page so we dont run into edit conflicts imtxt=imagepage.get(force=True)
@@ -676,7 +695,7 @@ else: commentText = nowCommonsMessage['_default']
- wikipedia.showDiff(imagepage.get(), imtxt + addTemplate) + pywikibot.showDiff(imagepage.get(), imtxt + addTemplate) imagepage.put(imtxt + addTemplate, comment = commentText)
def replaceUsage(self, imagepage, filename): @@ -696,10 +715,10 @@
def main(args): - wikipedia.output(u'WARNING: This is an experimental bot') - wikipedia.output(u'WARNING: It will only work on self published work images') - wikipedia.output(u'WARNING: This bot is still full of bugs') - wikipedia.output(u'WARNING: Use at your own risk!') + pywikibot.output(u'WARNING: This is an experimental bot') + pywikibot.output(u'WARNING: It will only work on self published work images') + pywikibot.output(u'WARNING: This bot is still full of bugs') + pywikibot.output(u'WARNING: Use at your own risk!')
generator = None; always = False @@ -708,7 +727,7 @@ # Load a lot of default generators genFactory = pagegenerators.GeneratorFactory()
- for arg in wikipedia.handleArgs(): + for arg in pywikibot.handleArgs(): if arg == '-nochecktemplate': checkTemplate = False else: @@ -743,4 +762,4 @@ try: main(sys.argv[1:]) finally: - wikipedia.stopme() + pywikibot.stopme()