jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/463455 )
Change subject: [doc] Add a common help string to flickrripper.py
......................................................................
[doc] Add a common help string to flickrripper.py
- remove usage() function
- move comments to related functions
- show error messages and warnings when needed
Bug: T199094
Change-Id: I7bd590f3226cd3eef1fdb915af33a1b122528aa5
---
M scripts/flickrripper.py
M tests/script_tests.py
M tox.ini
3 files changed, 55 insertions(+), 59 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py
index 61310db..1bd3ff5 100755
--- a/scripts/flickrripper.py
+++ b/scripts/flickrripper.py
@@ -1,21 +1,20 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-Tool to copy a flickr stream to Commons.
+A tool to transfer flickr photos to Wikimedia Commons.
-# Get a set to work on (start with just a username).
- * Make it possible to delimit the set (from/to)
-# For each image
- * Check the license
- * Check if it isn't already on Commons
- * Build suggested filename
- * Check for name collision and maybe alter it
- * Pull description from Flinfo
- * Show image and description to user
- * Add a nice hotcat lookalike for the adding of categories
- * Filter the categories
- * Upload the image
-
+ -group_id: specify group ID of the pool
+ -photoset_id: specify a photoset id
+ -user_id: give the user id of the flickrriper user
+ -start_id: the photo id to start with
+ -end_id: the photo id to end with
+ -tags: a tag to filter photo items (only one is supported)
+ -flickerreview add a flickr review template to the description
+ -reviewer: specify the reviewer
+ -override: override text for licence
+ -addcategory: specify a category
+ -removecategories remove all categories
+ -autonomous run bot in autonomous mode
"""
#
# (C) Multichill, 2009
@@ -47,12 +46,9 @@
from urllib import urlencode
try:
- import flickrapi # see:
http://stuvel.eu/projects/flickrapi
+ import flickrapi # see:
http://stuvel.eu/projects/flickrapi
except ImportError as e:
- print('This script requires the python flickrapi module. \n'
- 'See:
http://stuvel.eu/projects/flickrapi')
- print(e)
- sys.exit(1)
+ flickrapi = e
flickr_allowed_license = {
@@ -271,7 +267,19 @@
def processPhoto(flickr, photo_id='', flickrreview=False, reviewer='',
override='', addCategory='', removeCategories=False,
autonomous=False):
- """Process a single Flickr photo."""
+ """Process a single Flickr photo.
+
+ For each image:
+ * Check the license
+ * Check if it isn't already on Commons
+ * Build suggested filename
+ * Check for name collision and maybe alter it
+ * Pull description from Flinfo
+ * Show image and description to user
+ * Add a nice hotcat lookalike for the adding of categories
+ * Filter the categories
+ * Upload the image
+ """
if photo_id:
pywikibot.output(str(photo_id))
(photoInfo, photoSizes) = getPhoto(flickr, photo_id)
@@ -331,7 +339,11 @@
def getPhotos(flickr, user_id='', group_id='', photoset_id='',
start_id='', end_id='', tags=''):
- """Loop over a set of Flickr photos."""
+ """Loop over a set of Flickr photos.
+
+ Get a set to work on (start with just a username).
+ * Make it possible to delimit the set (from/to)
+ """
found_start_id = not start_id
#
https://www.flickr.com/services/api/flickr.groups.pools.getPhotos.html
@@ -386,21 +398,6 @@
return
-def usage():
- """
- Print usage information.
-
- TODO : Need more.
- """
- pywikibot.output('Flickrripper is a tool to transfer flickr photos to '
- 'Wikimedia Commons')
- pywikibot.output('-group_id:<group_id>\n')
- pywikibot.output('-photoset_id:<photoset_id>\n')
- pywikibot.output('-user_id:<user_id>\n')
- pywikibot.output('-tags:<tag>\n')
- return
-
-
def main(*args):
"""
Process command line arguments and invoke bot.
@@ -412,21 +409,6 @@
"""
local_args = pywikibot.handle_args(args)
- # Get the api key
- if not config.flickr['api_key']:
- pywikibot.output('Flickr api key not found! Get yourself an api key')
- pywikibot.output(
- 'Any flickr user can get a key at '
- 'https://www.flickr.com/services/api/keys/apply/')
- return
-
- if 'api_secret' in config.flickr and config.flickr['api_secret']:
- flickr = flickrapi.FlickrAPI(config.flickr['api_key'],
- config.flickr['api_secret'])
- else:
- pywikibot.output('Accessing public content only')
- flickr = flickrapi.FlickrAPI(config.flickr['api_key'])
-
group_id = ''
photoset_id = ''
user_id = ''
@@ -517,18 +499,32 @@
elif arg == '-autonomous':
autonomous = True
- if user_id or group_id or photoset_id:
+ if isinstance(flickrapi, Exception):
+ pywikibot.error('This script requires the python flickrapi module. \n'
+ 'See:
http://stuvel.eu/projects/flickrapi')
+
+ elif not config.flickr['api_key']:
+ pywikibot.warning('Flickr api key not found! Get yourself an api key\n'
+ 'Any flickr user can get a key at\n'
+ 'https://www.flickr.com/services/api/keys/apply/')
+
+ elif user_id or group_id or photoset_id:
+ if 'api_secret' in config.flickr and
config.flickr['api_secret']:
+ flickr = flickrapi.FlickrAPI(config.flickr['api_key'],
+ config.flickr['api_secret'])
+ else:
+ pywikibot.output('Accessing public content only')
+ flickr = flickrapi.FlickrAPI(config.flickr['api_key'])
+
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
- else:
- usage()
- pywikibot.output('Finished running')
- pywikibot.output('Total photos: ' + str(totalPhotos))
- pywikibot.output('Uploaded photos: ' + str(uploadedPhotos))
+ pywikibot.output('Finished running')
+ pywikibot.output('Total photos: ' + str(totalPhotos))
+ pywikibot.output('Uploaded photos: ' + str(uploadedPhotos))
if __name__ == '__main__':
diff --git a/tests/script_tests.py b/tests/script_tests.py
index af9e37b..735336a 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -376,6 +376,7 @@
_expected_failures = failed_dep_script_set
# -help tests may pass even when packages are required
+ _expected_failures.discard('flickrripper')
_expected_failures.discard('imageharvest')
_expected_failures.discard('isbn')
_expected_failures.discard('weblinkchecker')
@@ -402,7 +403,6 @@
_expected_failures = {
'catall', # stdout user interaction
- 'flickrripper', # Requires a flickr api key
'upload', # raises custom ValueError
}.union(failed_dep_script_set)
diff --git a/tox.ini b/tox.ini
index 2ab13a8..02de60f 100644
--- a/tox.ini
+++ b/tox.ini
@@ -202,7 +202,7 @@
scripts/commonscat.py : N803, N806, N802
scripts/data_ingestion.py : N803, N806, N802
scripts/fixing_redirects.py : N803, N806
- scripts/flickrripper.py : T001, N803, N806, N802
+ scripts/flickrripper.py : N803, N806, N802
scripts/freebasemappingupload.py: N802
scripts/harvest_template.py : T001, N802
scripts/imagecopy.py : N801, N803, N806, N802
--
To view, visit
https://gerrit.wikimedia.org/r/463455
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I7bd590f3226cd3eef1fdb915af33a1b122528aa5
Gerrit-Change-Number: 463455
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: jenkins-bot (75)