RyanKilkelly
RyanKilkelly

Reputation: 279

Printing out node info from an osmapi call in python

Here is my code so far, I want to use details obtained from flickr images and find if the geo-location is connected to a node. Then I want to use the osmapi to obtain the node info.

import flickrapi
import osmapi
import overpy
import geopy
from geopy.geocoders import Nominatim
import requests

api_key = "xxxxxxxxxxxxxxxxxxxxx"
secret_api_key = "xxxxxxx"
flickr = flickrapi.FlickrAPI(api_key, secret_api_key)

def obtainImages():

    photo_list = flickr.photos.search(api_key=api_key, accuracy = 15, has_geo=1, per_page = 100, extras = 'tags, url_s')

    for photo in photo_list[0]:

        id = str(photo.attrib['id'])
        tags = (photo.attrib['tags']).encode('utf-8')
        url = str(photo.attrib['url_s'])
        title = (photo.attrib['title']).encode('utf-8')

        photo_location = flickr.photos_geo_getLocation(photo_id=photo.attrib['id'])
        lat = float(photo_location[0][0].attrib['latitude'])
        lon = float(photo_location[0][0].attrib['longitude'])

        geolocator = Nominatim()
        location = geolocator.reverse("{}, {}".format(lat, lon))
        #print(location.raw)
        dict = location.raw
        osmid = dict.get('osm_id', 'default_value_if_null_here')
        osmtype = dict.get('osm_type', 'default_value_if_null_here')
        #print osmid
        #print osmtype

        if(osmtype == 'node'):
            node_info = requests.get("http://api.openstreetmap.org/api/0.6/node/"+ osmid)
            print node_info

obtainImages()

However when I run this i am obtaining the following

<Response [200]>
<Response [200]>
<Response [200]>
................
................
<Response [200]>

However what I want to obtain is a result such as the following:

< node id =" 592637238 " lat =" 47.1675211 " lon =" 9.5089882 "
       version ="2" changeset =" 6628391 "
       user =" phinret " uid =" 135921 "
       timestamp =" 2010 -12 -11 T19:20:16Z " >
   < tag k=" amenity " v=" bar " / >
   < tag k=" name " v=" Black Pearl " / >

Can anyone help in getting this information printed out, and specifically getting the tag variables. Anywhere I have commented out a print statement the variables are working fine.

Thanks in advance for your help, I really appreciate it as I am new to python

Upvotes: 1

Views: 470

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180441

You need the content, node_info is just the Response object, you need to call .content or .text to see what is returned:

print node_info.content

Upvotes: 1

Related Questions