Ladsgroup has uploaded a new change for review. https://gerrit.wikimedia.org/r/169493
Change subject: Rewrite getPhotos function in flickerripper ...................................................................... Rewrite getPhotos function in flickerripper It has been done to avoid using duplicate codes. See https://scrutinizer-ci.com/g/wikimedia/pywikibot-core/indices/373851/duplications/23725239 Change-Id: I4f000ed09d688f375b3681536d3ca214c2457e60 --- M scripts/flickrripper.py 1 file changed, 31 insertions(+), 67 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/93/169493/1 diff --git a/scripts/flickrripper.py b/scripts/flickrripper.py index 0f5302d..3b2da0f 100644 --- a/scripts/flickrripper.py +++ b/scripts/flickrripper.py @@ -425,29 +425,6 @@ per_page='100', page='1') pages = photos.find('photos').attrib['pages'] - for i in range(1, int(pages) + 1): - gotPhotos = False - while not gotPhotos: - try: - for photo in flickr.groups_pools_getPhotos( - group_id=group_id, user_id=user_id, tags=tags, - per_page='100', page=i - ).find('photos').getchildren(): - gotPhotos = True - if photo.attrib['id'] == start_id: - found_start_id = True - if found_start_id: - if photo.attrib['id'] == end_id: - pywikibot.output('Found end_id') - return - else: - yield photo.attrib['id'] - - except flickrapi.exceptions.FlickrError: - gotPhotos = False - pywikibot.output(u'Flickr api problem, sleeping') - time.sleep(30) - # https://www.flickr.com/services/api/flickr.photosets.getPhotos.html # Get the photos in a photoset elif photoset_id: @@ -455,56 +432,43 @@ per_page='100', page='1') pages = photos.find('photoset').attrib['pages'] - for i in range(1, int(pages) + 1): - gotPhotos = False - while not gotPhotos: - try: - for photo in flickr.photosets_getPhotos( - photoset_id=photoset_id, per_page='100', page=i - ).find('photoset').getchildren(): - gotPhotos = True - if photo.attrib['id'] == start_id: - found_start_id = True - if found_start_id: - if photo.attrib['id'] == end_id: - pywikibot.output('Found end_id') - return - else: - yield photo.attrib['id'] - - except flickrapi.exceptions.FlickrError: - gotPhotos = False - pywikibot.output(u'Flickr api problem, sleeping') - time.sleep(30) - # https://www.flickr.com/services/api/flickr.people.getPublicPhotos.html # Get the (public) photos uploaded by a user elif user_id: photos = flickr.people_getPublicPhotos(user_id=user_id, per_page='100', page='1') pages = photos.find('photos').attrib['pages'] - # flickrapi.exceptions.FlickrError - for i in range(1, int(pages) + 1): - gotPhotos = False - while not gotPhotos: - try: - for photo in flickr.people_getPublicPhotos( - user_id=user_id, per_page='100', page=i - ).find('photos').getchildren(): - gotPhotos = True - if photo.attrib['id'] == start_id: - found_start_id = True - if found_start_id: - if photo.attrib['id'] == end_id: - pywikibot.output('Found end_id') - return - else: - yield photo.attrib['id'] - - except flickrapi.exceptions.FlickrError: - gotPhotos = False - pywikibot.output(u'Flickr api problem, sleeping') - time.sleep(30) + for i in range(1, int(pages) + 1): + gotPhotos = False + while not gotPhotos: + if group_id: + gen = flickr.groups_pools_getPhotos( + group_id=group_id, user_id=user_id, tags=tags, + per_page='100', page=i + ).find('photos').getchildren() + elif photoset_id: + gen = flickr.photosets_getPhotos( + photoset_id=photoset_id, per_page='100', page=i + ).find('photoset').getchildren() + elif user_id: + gen = flickr.people_getPublicPhotos( + user_id=user_id, per_page='100', page=i + ).find('photos').getchildren() + try: + for photo in gen: + gotPhotos = True + if photo.attrib['id'] == start_id: + found_start_id = True + if found_start_id: + if photo.attrib['id'] == end_id: + pywikibot.output('Found end_id') + return + else: + yield photo.attrib['id'] + except flickrapi.exceptions.FlickrError: + gotPhotos = False + pywikibot.output(u'Flickr api problem, sleeping') + time.sleep(30) return -- To view, visit https://gerrit.wikimedia.org/r/169493 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4f000ed09d688f375b3681536d3ca214c2457e60 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ladsgroup <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
