def find_photo_for_date(date, flickr, nsid): title = str(date) # yyyymmdd filename = os.path.join(str(args.year), title + ".jpg") if os.path.exists(filename): print("\tFound file") else: today = datetime.datetime.now() today = datetime.date(today.year, today.month, today.day) if date > today: print("\tIn the future") black_pixel(filename) return photo = flickr_utils.most_interesting_today_in( flickr, nsid, date.year, args.size, date) if photo is not None: print("\tFound photo") url = flickr_utils.photo_url(flickr, photo, args.size) attempts = 0 while(attempts <= 5): try: flickr_utils.download(url, title, True, directory=str(args.year)) break except Exception as e: print("Error: %s" % repr(e)) print("Try again") attempts += 1 else: print("\tNo photo") black_pixel(filename)
def find_photo_for_date(date, flickr, nsid): title = str(date) # yyyymmdd filename = os.path.join(str(args.year), title + ".jpg") if os.path.exists(filename): print("\tFound file") else: today = datetime.datetime.now() today = datetime.date(today.year, today.month, today.day) if date > today: print("\tIn the future") black_pixel(filename) return photo = flickr_utils.most_interesting_today_in(flickr, nsid, date.year, args.size, date) if photo is not None: print("\tFound photo") url = flickr_utils.photo_url(flickr, photo, args.size) attempts = 0 while (attempts <= 5): try: flickr_utils.download(url, title, True, directory=str(args.year)) break except Exception as e: print("Error: %s" % repr(e)) print("Try again") attempts += 1 else: print("\tNo photo") black_pixel(filename)
def flickr_search_downloadr(text, tags, user_id, sort, quantity, number, size, title, noclobber, outdir): flickr = flickr_init() i = 0 number = None filenames = [] for photo in flickr.walk( tag_mode='all', # privacy_filter='1', # public # max_taken_date='2009-02-07', user_id=user_id, text=text, tags=tags, sort=sort): i += 1 if quantity and i > quantity: return filenames if number: number = str(i).zfill(6) photo_id = photo.attrib['id'] photo_info = flickr.photos_getInfo(photo_id=photo_id) photo_info = photo_info[0] secret = photo_info.attrib['secret'] if size == 'o': if 'originalsecret' in photo_info.attrib: secret = photo_info.attrib['originalsecret'] else: size = 'b' # Next best if title: photo_title = photo.attrib['title'] else: photo_title = None filename = flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_%s.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], secret, size), photo_title, noclobber, number, directory=outdir) filenames.append(filename) return filenames
def flickr_search_downloadr(text, tags, user_id, sort, quantity, number, size, title, noclobber, outdir): flickr = flickr_init() i = 0 number = None filenames = [] for photo in flickr.walk( tag_mode='all', # privacy_filter='1', # public # max_taken_date='2009-02-07', user_id=user_id, text=text, tags=tags, sort=sort): i += 1 if quantity and i > quantity: return filenames if number: number = str(i).zfill(6) photo_id = photo.attrib['id'] photo_info = flickr.photos_getInfo(photo_id=photo_id) photo_info = photo_info[0] secret = photo_info.attrib['secret'] if size == 'o': if'originalsecret' in photo_info.attrib: secret = photo_info.attrib['originalsecret'] else: size = 'b' # Next best if title: photo_title = photo.attrib['title'] else: photo_title = None filename = flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_%s.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], secret, size), photo_title, noclobber, number, directory=outdir) filenames.append(filename) return filenames
# If you ask for a page higher than 10,000, # the API just returns page 10,000 if random_integer <= 10000: # Use pages of 1 photo_page = flickr.people_getPublicPhotos( user_id=user_nsid, per_page=1, page=random_integer) photo = photo_page.getchildren()[0].find('photo') else: # Use pages of 500, the maximum page, offset = divmod(random_integer, 500) photo_page = flickr.people_getPublicPhotos( user_id=user_nsid, per_page=500, page=page) photo = photo_page.getchildren()[0][offset] random_photos.append(photo) # TODO? Some photos may not be found for some reason (private, etc), # so instead could have a while until the required number have # been actually downloaded. for photo in random_photos: url = flickr_utils.photo_url(photo, args.size) if args.title: photo_title = photo.attrib['title'] else: photo_title = None flickr_utils.download(url, photo_title, args.noclobber) # End of file
if args.number: number = str(page-1) + str(i + 1).zfill(len(total)) photo_id = photo.attrib['id'] photo_info = flickr.photos_getInfo(photo_id=photo_id) photo_info = photo_info[0] secret = photo_info.attrib['secret'] oSecret = photo_info.attrib['originalsecret'] if args.title: photo_title = photo.attrib['title'] else: photo_title = None if args.directory: photo_directory = photo_set.attrib['title'] else: photo_directory = None if args.size == "o": flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], oSecret), photo_title, args.noclobber, number, photo_directory) else: flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_%s.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], secret, args.size), photo_title, args.noclobber, number, photo_directory) # End of file
if args.number: number = str(page - 1) + str(i + 1).zfill(len(total)) photo_id = photo.attrib['id'] photo_info = flickr.photos_getInfo(photo_id=photo_id) photo_info = photo_info[0] secret = photo_info.attrib['secret'] oSecret = photo_info.attrib['originalsecret'] if args.title: photo_title = photo.attrib['title'] else: photo_title = None if args.directory: photo_directory = photo_set.attrib['title'] else: photo_directory = None if args.size == "o": flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_o.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], oSecret), photo_title, args.noclobber, number, photo_directory) else: flickr_utils.download( "http://farm%s.static.flickr.com/%s/%s_%s_%s.jpg" % (photo.attrib['farm'], photo.attrib['server'], photo.attrib['id'], secret, args.size), photo_title, args.noclobber, number, photo_directory) # End of file