From 4b7bb27a582f79b2dea45dfd7f60d432dc4f085a Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Fri, 15 Jul 2022 17:26:31 -0400 Subject: [PATCH] Try/catch Flickr errors --- scripts/utils/notifications.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index dfed537..e09cdec 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -50,13 +50,16 @@ def sendAppriseNotifications(species, confidence, path, date, time, week, latitu if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body: if not comName in flickr_images: - # 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' - resp = requests.get(url=url) - data = resp.json()["photos"]["photo"][0] + try: + # 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' + resp = requests.get(url=url) + data = resp.json()["photos"]["photo"][0] - 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 + 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 + except ValueError: + image_url = None else: image_url = flickr_images[comName]