Anshoe has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/181126

Change subject: Added Batch Functionality to scripts/flickrripper.py and added 
UTF-8 support to pywikibot/version.py
......................................................................

Added Batch Functionality to scripts/flickrripper.py and added UTF-8
support to pywikibot/version.py

Added batch functionality to flickrripper.py , so that it can now upload
multiple photos at a time.

version.py throwed an error during a local test of flickrripper.py , due
to lack of mentioning of the encoding type. Fixed.

Change-Id: Idce35550242b5929023e4abb2afc479e14ecfaf8
---
M pywikibot/version.py
M scripts/flickrripper.py
2 files changed, 58 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/26/181126/1

diff --git a/pywikibot/version.py b/pywikibot/version.py
index c0a93dd..e7debe4 100644
--- a/pywikibot/version.py
+++ b/pywikibot/version.py
@@ -14,6 +14,7 @@
 import time
 import datetime
 import subprocess
+import codecs
 
 import pywikibot.config2 as config
 
@@ -270,7 +271,7 @@
     mtime = None
     fn = os.path.join(_program_dir, filename)
     if os.path.exists(fn):
-        with open(fn, 'r') as f:
+        with codecs.open(fn, 'r', "UTF-8") as f:
             for line in f.readlines():
                 if line.find('__version__') == 0:
                     exec(line)
diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py
index cad7b1d..d8b0531 100644
--- a/scripts/flickrripper.py
+++ b/scripts/flickrripper.py
@@ -291,57 +291,60 @@
     return description
 
 
-def processPhoto(flickr=None, photo_id=u'', flickrreview=False, reviewer=u'',
+def processPhoto(flickr=None, photo_urls=[], flickrreview=False, reviewer=u'',
                  override=u'', addCategory=u'', removeCategories=False,
                  autonomous=False):
     """Process a single Flickr photo."""
-    if photo_id:
-        pywikibot.output(str(photo_id))
-        (photoInfo, photoSizes) = getPhoto(flickr, photo_id)
-    if isAllowedLicense(photoInfo) or override:
-        # Get the url of the largest photo
-        photoUrl = getPhotoUrl(photoSizes)
-        # Should download the photo only once
-        photo = downloadPhoto(photoUrl)
+    photo_urls_to_be_uploaded = []
+    for photo_id in photo_urls :
+        if photo_id:
+            pywikibot.output(str(photo_id))
+            (photoInfo, photoSizes) = getPhoto(flickr, photo_id)
+        if isAllowedLicense(photoInfo) or override:
+            # Get the url of the largest photo
+            photoUrl = getPhotoUrl(photoSizes)
+            photo_urls_to_be_uploaded.append(photoUrl)
+            # Should download the photo only once
+            photo = downloadPhoto(photoUrl)
 
-        # Don't upload duplicate images, should add override option
-        duplicates = findDuplicateImages(photo)
-        if duplicates:
-            pywikibot.output(u'Found duplicate image at %s' % duplicates.pop())
-        else:
-            filename = getFilename(photoInfo)
-            flinfoDescription = getFlinfoDescription(photo_id)
-            photoDescription = buildDescription(flinfoDescription,
-                                                flickrreview, reviewer,
-                                                override, addCategory,
-                                                removeCategories)
-            # pywikibot.output(photoDescription)
-            if not autonomous:
-                (newPhotoDescription, newFilename, skip) = Tkdialog(
-                    photoDescription, photo, filename).run()
+            # Don't upload duplicate images, should add override option
+            duplicates = findDuplicateImages(photo)
+            if duplicates:
+                pywikibot.output(u'Found duplicate image at %s' % 
duplicates.pop())
             else:
-                newPhotoDescription = photoDescription
-                newFilename = filename
-                skip = False
-        # pywikibot.output(newPhotoDescription)
-        # if (pywikibot.Page(title=u'File:'+ filename, 
site=pywikibot.Site()).exists()):
-        # I should probably check if the hash is the same and if not upload it 
under a different name
-        # pywikibot.output(u'File:' + filename + u' already exists!')
-        # else:
-            # Do the actual upload
-            # Would be nice to check before I upload if the file is already at 
Commons
-            # Not that important for this program, but maybe for derived 
programs
-            if not skip:
-                bot = upload.UploadRobot(photoUrl,
-                                         description=newPhotoDescription,
-                                         useFilename=newFilename,
-                                         keepFilename=True,
-                                         verifyDescription=False)
-                bot.upload_image(debug=False)
-                return 1
-    else:
-        pywikibot.output(u'Invalid license')
-    return 0
+                filename = getFilename(photoInfo)
+                flinfoDescription = getFlinfoDescription(photo_id)
+                photoDescription = buildDescription(flinfoDescription,
+                                                    flickrreview, reviewer,
+                                                    override, addCategory,
+                                                    removeCategories)
+                # pywikibot.output(photoDescription)
+                if not autonomous:
+                    (newPhotoDescription, newFilename, skip) = Tkdialog(
+                        photoDescription, photo, filename).run()
+                else:
+                    newPhotoDescription = photoDescription
+                    newFilename = filename
+                    skip = False
+            # pywikibot.output(newPhotoDescription)
+            # if (pywikibot.Page(title=u'File:'+ filename, 
site=pywikibot.Site()).exists()):
+            # I should probably check if the hash is the same and if not 
upload it under a different name
+            # pywikibot.output(u'File:' + filename + u' already exists!')
+            # else:
+                # Do the actual upload
+                # Would be nice to check before I upload if the file is 
already at Commons
+                # Not that important for this program, but maybe for derived 
programs
+                if not skip:
+                    bot = upload.UploadRobot(photo_urls_to_be_uploaded,
+                                             description=newPhotoDescription,
+                                             useFilename=newFilename,
+                                             keepFilename=True,
+                                             verifyDescription=False)
+                    bot.upload_image(debug=False)
+                    return len(photo_urls_to_be_uploaded)
+        else:
+            pywikibot.output(u'Invalid license')
+        return 0
 
 
 class Tkdialog:
@@ -621,13 +624,16 @@
         elif arg == '-autonomous':
             autonomous = True
 
+    photo_urls = []
+
     if user_id or group_id or photoset_id:
         for photo_id in getPhotos(flickr, user_id, group_id, photoset_id,
                                   start_id, end_id, tags):
-            uploadedPhotos += processPhoto(flickr, photo_id, flickrreview,
-                                           reviewer, override, addCategory,
-                                           removeCategories, autonomous)
-            totalPhotos += 1
+            photo_urls.append(photo_id)
+        uploadedPhotos += processPhoto(flickr, photo_urls, flickrreview,
+                                        reviewer, override, addCategory,
+                                        removeCategories, autonomous)
+        totalPhotos += len(photo)
     else:
         usage()
     pywikibot.output(u'Finished running')

-- 
To view, visit https://gerrit.wikimedia.org/r/181126
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idce35550242b5929023e4abb2afc479e14ecfaf8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Anshoe <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to