mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-24 00:06:04 +02:00
Correct FlickrImage
This commit is contained in:
@@ -62,14 +62,14 @@ def automatic_mqtt_publish(file, detections):
|
|||||||
bird['ClipName'] = path
|
bird['ClipName'] = path
|
||||||
bird['url'] = bird_lookup_url_base + detection.scientific_name
|
bird['url'] = bird_lookup_url_base + detection.scientific_name
|
||||||
|
|
||||||
|
# Flickimage
|
||||||
image_url = ""
|
image_url = ""
|
||||||
common_name = detection.common_name
|
common_name = high_bird_fields[3]
|
||||||
if len(settings_dict.get('FLICKR_API_KEY', '')) > 0:
|
if len(settings_dict.get('FLICKR_API_KEY')) > 0:
|
||||||
if common_name not in flickr_images:
|
if common_name not in flickr_images:
|
||||||
try:
|
try:
|
||||||
headers = {'User-Agent': 'Python_Flickr/1.0'}
|
headers = {'User-Agent': 'Python_Flickr/1.0'}
|
||||||
url = ('https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=' +
|
url = ('https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + str(settings_dict.get('FLICKR_API_KEY')) +
|
||||||
str(settings_dict.get('FLICKR_API_KEY')) +
|
|
||||||
'&text=' + str(common_name) + ' bird&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1')
|
'&text=' + str(common_name) + ' 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 = requests.get(url=url, headers=headers, timeout=10)
|
||||||
|
|
||||||
@@ -77,12 +77,12 @@ def automatic_mqtt_publish(file, detections):
|
|||||||
data = resp.json()["photos"]["photo"][0]
|
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'
|
image_url = 'https://farm'+str(data["farm"])+'.static.flickr.com/'+str(data["server"])+'/'+str(data["id"])+'_'+str(data["secret"])+'_n.jpg'
|
||||||
flickr_images[common_name] = image_url
|
flickr_images[comName] = image_url
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("FLICKR API ERROR: " + str(e))
|
print("FLICKR API ERROR: "+str(e))
|
||||||
image_url = ""
|
image_url = ""
|
||||||
else:
|
else:
|
||||||
image_url = flickr_images[common_name]
|
image_url = flickr_images[comName]
|
||||||
bird['Flickrimage'] = image_url
|
bird['Flickrimage'] = image_url
|
||||||
|
|
||||||
json_bird = json.dumps(bird)
|
json_bird = json.dumps(bird)
|
||||||
|
|||||||
Reference in New Issue
Block a user