Try/catch Flickr errors

This commit is contained in:
ehpersonal38
2022-07-15 17:26:31 -04:00
parent 0c9bc94ae2
commit 4b7bb27a58
+3
View File
@@ -50,6 +50,7 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body: if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
if not comName in flickr_images: if not comName in flickr_images:
try:
# TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here # TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here
url = 'https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key='+str(settings_dict.get('FLICKR_API_KEY'))+'&text='+str(comName)+'&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1' url = 'https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key='+str(settings_dict.get('FLICKR_API_KEY'))+'&text='+str(comName)+'&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1'
resp = requests.get(url=url) resp = requests.get(url=url)
@@ -57,6 +58,8 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu
image_url = 'https://farm'+str(data["farm"])+'.static.flickr.com/'+str(data["server"])+'/'+str(data["id"])+'_'+str(data["secret"])+'_n.jpg' image_url = 'https://farm'+str(data["farm"])+'.static.flickr.com/'+str(data["server"])+'/'+str(data["id"])+'_'+str(data["secret"])+'_n.jpg'
flickr_images[comName] = image_url flickr_images[comName] = image_url
except ValueError:
image_url = None
else: else:
image_url = flickr_images[comName] image_url = flickr_images[comName]