def deleteAllPics( ): global user try: user = flickr.test_login() logging.debug(user.id) except: logging.error(sys.exc_info()[0]) return None if(deleteAll.startswith('true') == False): return #check again to be sure if to go one logging.debug('deleteAll: Started Delete') retries = 0 #this may take very long time !!!! while (retries < 3): try: photos = [] logging.debug(user.id) np = flickr.photos_search_pages(user_id=user.id, auth=all, per_page="500") numPages = int(np) i = 1 logging.debug("found %d num pages" % numPages) while ( numPages > 0): spage = str(i) photos.extend(flickr.photos_search(user_id=user.id, auth=all, per_page="500", page=spage)) logging.debug( "added %d page to %d pic" % (i, len(photos))) numPages = numPages - 1 i = i + 1 logging.debug( "got all %d pics to delete" % len(photos)) break except: logging.error("deleteAll: Flickr error while searching ....retrying") logging.error(sys.exc_info()[0]) retries = retries + 1 if (not photos or len(photos) == 0): logging.debug("deleteAll: No files in Flickr to delete" ) return None logging.debug("deleteAll: found %d media files to delete" % (len(photos))) while (len(photos)>1): try: photos.pop().delete() print "deleting pic " logging.debug("deleteAll: Removed one image... %d images to go" % (len(photos))) except: logging.error("deleteAll: Flickr error while deleting image") logging.error(sys.exc_info()[0]) logging.debug("deleteAll: DONE DELETING - NOTHING ELSE TO DO - EXITING") os._exit(1)
start = timer() if len(sys.argv)>1: lic = sys.argv[1] date = sys.argv[2] else: print 'no tag specified' firstattempt = 0 # downloading image data #f = flickr.people_getPublicPhotos(min_upload_date="2015-03-20", max_upload_date="2015-03-20", license=lic) while firstattempt < 3: try: #get the photos f = flickr.photos_search(min_upload_date=date, max_upload_date=date, license=lic, per_page="1") #get the total pages fn = flickr.photos_search_pages(min_upload_date=date, max_upload_date=date, license=lic, per_page="2") #loop through the pages print 'TOTAL', fn, len(f) for z in range(0,int(fn)): pageattempts=0 while pageattempts < 3: try: f = flickr.photos_search(min_upload_date=date, max_upload_date=date, license=lic, page=z+1, per_page="2") #print 'license:', lic urllist = [] #store a list of what was downloaded fl = open('urllist.txt', 'w') fail = open('failed.txt', 'w') counter = 0 attempts = 0 # downloading images for k in f:
for row in rows: print "Grid #"+str(row.OID) feat = row.getValue(shapeName) extent = feat.extent bbox = [] bbox.append(extent.XMin) bbox.append(extent.YMin) bbox.append(extent.XMax) bbox.append(extent.YMax) bbox = str(bbox) bbox = bbox.replace("]","") bbox = bbox.replace("[","") z = 0 pages = flickr.photos_search_pages(user_id='', auth=False, tags='', tag_mode='', text='',\ min_upload_date='946681200', max_upload_date='',\ min_taken_date='', max_taken_date='', \ license='', per_page='500', page='', sort='',\ safe_search='', content_type='', bbox=bbox, woe_id='' ) pages = int(pages) print str(pages) + " Pages have been found for bbox "+ str(bbox) while z <= pages: try: x = z x = "'"+str(x)+"'" list = flickr.photos_search(user_id='', auth=False, tags='', tag_mode='', text='',\ min_upload_date='946681200', max_upload_date='',\ min_taken_date='', max_taken_date='', \ license='', per_page='500', page=z, sort='',\ safe_search='', content_type='', bbox=bbox,woe_id='' ) print "API Call #"+str(z)+" successful on bbboxv2"
def number_of_photos_for_tags(tags): return int(flickr.photos_search_pages(tags=tags, user_id='britishlibrary', sort='relevant'))*100