def isOkToAdd(photo_id): info = flickr.photos.getInfo(photo_id=photo_id)['photo'] is_public = info['visibility']['ispublic'] safety_level = info['safety_level'] try: exif = getExif(photo_id, 0) lens_model = getLensModel(exif) focal_length = getFocalLength(exif) except: return False if is_public and safety_level == '0' and lens_model in data.lens_models and focal_length in data.focal_lengths: return True else: return False
def addPhoto(report_file_name, html_file_name, remove_file_name, pool, page_number, photo_number): photo_id = pool['photos']['photo'][photo_number]['id'] photo_title = pool['photos']['photo'][photo_number]['title'] photo_owner = pool['photos']['photo'][photo_number]['ownername'] owner_id = pool['photos']['photo'][photo_number]['owner'] try: photo_url = flickr.people.getInfo(api_key=api_key, user_id=owner_id)['person']['photosurl']['_content'] + photo_id date_added = pool['photos']['photo'][photo_number]['dateadded'] except: photo_url = '' date_added = '0000000000' try: exif = getExif(photo_id, 0) lens_model = getLensModel(exif) focal_length = getFocalLength(exif) except: lens_model = 'NO EXIF' focal_length = 'NO EXIF' asian = photo_title.strip(data.eastern_chars) no_asian = photo_title.replace(asian,'') date = datetime.fromtimestamp(int(date_added)).strftime('%d/%m/%Y') report_file = open(report_file_name,'a') report_file.write('| {0:3} | {1:50.50} | {2:35.35} | {3:40.40} | {4:>10.10} | {5:>10.10} '.format(photo_number+1, no_asian, photo_owner, lens_model, focal_length, date)) if (not(lens_model in lens_models)) or (not(focal_length in focal_lengths)): if lens_model != 'NO EXIF' and focal_length != 'NO EXIF' and lens_model != '' and focal_length != '': report_file.write('| REMOVE |\n') addPhotoToRemove(remove_file_name, page_number, photo_number+1, photo_id, owner_id, photo_title, photo_owner, lens_model, focal_length) else: report_file.write('| REVIEW |\n') else: report_file.write('| KEEP |\n') report_file.close() report_file = open(html_file_name,'a') report_file.write('| {0:3} | {1:50.50} | {2:35.35} | {3:40.40} | {4:>10.10} | {5:>10.10} '.format(photo_number+1, no_asian, photo_owner, lens_model, focal_length, date).replace(' ',' ')) if (not(lens_model in lens_models)) or (not(focal_length in focal_lengths)): if lens_model != 'NO EXIF' and focal_length != 'NO EXIF' and lens_model != '' and focal_length != '': report_file.write('| <ahref=\"{}\"target=\"_blank\">REMOVE</a> |<br>\n'.format(photo_url).replace(' ',' ').replace('ahref','a href').replace('target', ' target')) else: report_file.write('| <ahref=\"{}\"target=\"_blank\">REVIEW</a> |<br>\n'.format(photo_url).replace(' ',' ').replace('ahref','a href').replace('target', ' target')) else: report_file.write('| KEEP |<br>\n'.replace(' ',' ')) report_file.close()
def isExifMissing(photo_id, photo_title): if not hasTag(photo_id, skip_tag): try: exif = getExif(photo_id, 0) camera_maker = getCameraMaker(exif) camera_model = getCameraModel(exif) lens_model = getLensModel(exif) focal_length = getFocalLength(exif) aperture = getAperture(exif) iso = getISO(exif) except: print('ERROR: Unable to get information for photo \'{0}\''.format( photo_title)) return True # Do not edit the next 1st, 2nd and 4th lines. Edit the 3rd line to include any additional condition if camera_model == '' or (lens_model == '' and (camera_maker != 'NIKON' and camera_maker != 'Fujifilm')) \ or (focal_length == '' and camera_maker != 'Vivitar') or ((aperture == '' or iso == '') \ and (camera_maker != 'Vivitar' and camera_maker != 'Fujifilm')): return True else: return False else: print("SKIPPED!") return False
total_photos = int(photos['photos']['total']) print("Searching for best lens... Please, wait.") photo = 0 lenses = data.lenses for pg in range(1, npages + 1): page = flickr.people.getPhotos(user_id=user_id, page=pg) ppage = len(page['photos']['photo']) for ph in range(0, ppage): photo = photo + 1 photo_id = page['photos']['photo'][ph]['id'] try: exif = getExif(photo_id, 0, False) camera_maker = getCameraMaker(exif) camera_model = getCameraModel(exif) focal_length = getFocalLength(exif) if focal_length == '': focal_length = 0 else: focal_length = float(focal_length.replace(' mm', '')) except: break if camera_maker == data.camera['maker'] and data.camera[ 'system'] in camera_model: for i in range(len(lenses)): if focal_length >= lenses[i][1] and focal_length <= lenses[i][ 2]: n = lenses[i][3]
def processPhoto(photo_id, photo_title, user_id): # Favorites of Others Set try: favorites = flickr.photos.getFavorites(photo_id=photo_id) photo_favs = int(favorites['photo']['total']) in_set = isInSet(photo_id, fav_others_id) print('favorites: {0}\n'.format(photo_favs), end='') if not in_set and photo_favs >= 1 and not hasTag(photo_id, tag): addPhotoToSet(fav_others_id, photo_id, photo_title) if in_set and (photo_favs == 0 or hasTag(photo_id, tag)): remPhotoFromSet(fav_others_id, photo_id, photo_title) except: print('ERROR: Unable to get information for photo \'{0}\''.format(photo_title)) # Galleries Set try: galleries = flickr.galleries.getListForPhoto(photo_id=photo_id) photo_expos = int(galleries['galleries']['total']) in_set = isInSet(photo_id, galleries_id) print('galleries: {0}\n'.format(photo_expos), end='') if not in_set and photo_expos >= 1 and not hasTag(photo_id, tag): addPhotoToSet(galleries_id, photo_id, photo_title) if in_set and (photo_expos == 0 or hasTag(photo_id, tag)): remPhotoFromSet(gallleries_id, photo_id, photo_title) except: print('ERROR: Unable to get information for photo \'{0}\''.format(photo_title)) # Lenses Exif Sets exif = getExif(photo_id, 0) try: focal_length = getFocalLength(exif) aperture = getAperture(exif) print('focal length: {0}\n'.format(focal_length), end='') print('aperture: {0}\n'.format(aperture), end='') except: print('ERROR: Unable to get information for photo \'{0}\''.format(photo_title)) focal_length = '' aperture = '' pass ## @10mm if focal_length == '10.0 mm': try: at10mm_set = flickr.photosets.getPhotos(photoset_id=at10mm_id, user_id=user_id) at10mm_title = at10mm_set['photoset']['title'] in_set = isInSet(photo_id, at10mm_id) if not in_set: addPhotoToSet(at10mm_id, photo_id, photo_title) except Exception as e: print('ERROR: Unable to add photo \'{0}\' to set \'{1}\''.format(photo_title, at10mm_title)) print(e) ## @250mm if (focal_length == '250.0 mm' and not hasTag(photo_id, "Kenko TELEPLUS HD DGX 1.4x") and not hasTag(photo_id, "Kenko TELEPLUS HD DGX 2x")) \ or (focal_length == '350.0 mm' and hasTag(photo_id, "Kenko TELEPLUS HD DGX 1.4x")) \ or (focal_length == '500.0 mm' and hasTag(photo_id, "Kenko TELEPLUS HD DGX 2x")) \ or (focal_length == '700.0 mm' and hasTag(photo_id, "Kenko TELEPLUS HD DGX 2x") and hasTag(photo_id, "Kenko TELEPLUS HD DGX 1.4x")): try: at250mm_set = flickr.photosets.getPhotos(photoset_id=at250mm_id, user_id=user_id) at250mm_title = at250mm_set['photoset']['title'] in_set = isInSet(photo_id, at250mm_id) if not in_set: addPhotoToSet(at250mm_id, photo_id, photo_title) except Exception as e: print('ERROR: Unable to add photo \'{0}\' to set \'{1}\''.format(photo_title, at250mm_title)) print(e) ## @f1.8 if aperture == '1.8': try: at1p8_set = flickr.photosets.getPhotos(photoset_id=at1p8_id, user_id=user_id) at1p8_title = at1p8_set['photoset']['title'] in_set = isInSet(photo_id, at1p8_id) if not in_set: addPhotoToSet(at1p8_id, photo_id, photo_title) except Exception as e: print('ERROR: Unable to add photo \'{0}\' to set \'{1}\''.format(photo_title, at1p8_title)) print(e)