use the api to get the image
This commit is contained in:
@@ -102,22 +102,12 @@ def sendAppriseNotifications(species, confidence, confidencepct, path,
|
|||||||
friendlyurl = "[Listen here]("+listenurl+")"
|
friendlyurl = "[Listen here]("+listenurl+")"
|
||||||
image_url = ""
|
image_url = ""
|
||||||
|
|
||||||
if len(settings_dict.get('FLICKR_API_KEY')) > 0 and "$flickrimage" in body:
|
if "$flickrimage" in body:
|
||||||
if comName not in flickr_images:
|
if comName not in flickr_images:
|
||||||
try:
|
try:
|
||||||
# TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here
|
url = f"http://localhost/api/v1/image/{sciName}"
|
||||||
headers = {'User-Agent': 'Python_Flickr/1.0'}
|
resp = requests.get(url=url, timeout=10).json()
|
||||||
url = ('https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + str(settings_dict.get('FLICKR_API_KEY')) +
|
flickr_images[comName] = resp['data']['image_url']
|
||||||
'&text=' + str(comName) +
|
|
||||||
' bird&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1')
|
|
||||||
resp = requests.get(url=url, headers=headers, timeout=10)
|
|
||||||
|
|
||||||
resp.encoding = "utf-8"
|
|
||||||
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
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("FLICKR API ERROR: "+str(e))
|
print("FLICKR API ERROR: "+str(e))
|
||||||
image_url = ""
|
image_url = ""
|
||||||
|
|||||||
Reference in New Issue
Block a user