flickr - Run only if geo-info available in python -
here snippet of code:
import flickrapi api_key = "xxxxxxxxxxxxxxxxxxxxx" secret_api_key = "xxxxxxxxxx" flickr = flickrapi.flickrapi(api_key, secret_api_key) def obtainimages3(): group_list = flickr.groups.search (api_key=api_key, text = 'paris', per_page = 10) group in group_list[0]: group_images = flickr.groups.pools.getphotos (api_key=api_key, group_id = group.attrib['nsid'], extras = 'geo, tags, url_s') image in group_images[0]: url = image.attrib['url_s'] tags = image.attrib['tags'] if image.attrib['geo'] != 'null': photo_location = flickr.photos_geo_getlocation(photo_id=image.attrib['id']) lat = float(photo_location[0][0].attrib['latitude']) lon = float(photo_location[0][0].attrib['longitude']) i want information images if , if have geo-tag connected them. tried line if image.attrib['geo'] != 'null' don't think works. can suggest way might able it, in advance!
replace if image.attrib['geo']!='null' condition try , exception block below. since api returns data in json format can check presence of key using:
try: image.attrib['geo'] photo_location=flickr.photos_geo_getlocation(photo_id=image.attrib['id']) lat = float(photo_location[0][0].attrib['latitude']) lon = float(photo_location[0][0].attrib['longitude']) except keyerror: pass
Comments
Post a Comment