2016-02-01 77 views
1

這裏是我的代碼,我想使用從flickr圖像獲取的細節,並查找地理位置是否連接到節點。然後我想使用osmapi來獲取節點信息。在python中打印osmapi調用的節點信息

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() 

然而,當我運行這個我得出以下

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

但是我想要得到的結果如下所示:

< 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 "/> 

可以得到任何人的幫助這些信息打印出來,特別是獲取標籤變量。任何地方,我已經註釋掉了一個print語句,變量工作正常。

預先感謝您的幫助,我真的很感激它,因爲我是新來的蟒蛇

回答

1

你所需要的內容,node_info只是Response對象,你需要調用。內容或的.text看看有什麼返回:

print node_info.content

+0

當我與「打印node_info.content()」跑了,我有以下錯誤:「類型錯誤:‘海峽’對象不是可調用」,當我跑了「打印node_info.text ()'我得到了錯誤:'TypeError:'unicode'對象不可調用'。你有任何建議來解決這個問題,或者這意味着其他地方有一個錯誤。感謝您的幫助 – RyanKilkelly

+0

@RyanKilkellym對不起,我錯誤地添加了parens。編輯將工作 –

+0

謝謝你已經爲我工作! – RyanKilkelly