mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-19 20:40:32 +02:00
Add flickrimage to mqtt https://github.com/alexbelgium/hassio-addons/issues/1516
This commit is contained in:
@@ -116,6 +116,28 @@ for row in file_row_generator(syslog):
|
||||
# build a url from scientific name of bird that can be used to lookup info about bird
|
||||
bird['url'] = bird_lookup_url_base + high_bird_fields[2].replace(' ', '_')
|
||||
|
||||
# Flickimage
|
||||
image_url = ""
|
||||
if len(settings_dict.get('FLICKR_API_KEY')) > 0:
|
||||
if comName not in flickr_images:
|
||||
try:
|
||||
headers = {'User-Agent': 'Python_Flickr/1.0'}
|
||||
url = ('https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + str(settings_dict.get('FLICKR_API_KEY')) +
|
||||
'&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:
|
||||
print("FLICKR API ERROR: "+str(e))
|
||||
image_url = ""
|
||||
else:
|
||||
image_url = flickr_images[comName]
|
||||
bird['Image'] = image_url
|
||||
|
||||
# convert to json string we can sent to mqtt
|
||||
json_bird = json.dumps(bird)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user