<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:10pt">Hi Phanindra,<br><br>This is a late answer but I took time to test the solution using the urllib2 module to send a request to a website and extract data. I give you an example with the Overpass API.<br><br>Using Overpass is a very interesting solution to extract for a bbox and pass the result to Python. It is possible to output in json and then convert easily to Python dictionary objects. The python script example below uses the urllib2 module to send a request and read the result. <br><br>The url contains the instructions sent to the Overpass API. In this example, The nodes that have a name Tag are extracted for the given bbox.<br><br>In the dictionary, elements contains the list of elements extracted from OSM. The string function .decode('utf8') let's decode and print
correctly the UTF8 characters.<br> <div><span style="font-style:italic;color:rgb(0, 0, 191);font-weight:bold;">Pierre <br></span></div><div style="color: rgb(0, 0, 191); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: italic;"><br></div><div style="color: rgb(0, 0, 191); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: italic;">Python script</div><div style="color: rgb(0, 0, 191); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: italic;">---------------------------------------------------------------------------------------------------------------------------------------------------<br></div><div style="color: rgb(0, 0, 191); font-size: 13.3333px;
font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent;">import urllib2,urllib,json<br># space replaced with + sign<br>url='http://overpass.osm.rambler.ru/cgi/interpreter?data=[out:json];(node[name](45.37301118463942,-72.80742645263672,45.416286468478475,-72.71095275878906););out+body;'<br><br>try:<br> print "try request"<br> overpass_response = urllib2.urlopen(url)<br> print "info"<br> print overpass_response.info()<br> #overpass_response = urllib2.urlopen(url_o)<br>except urllib2.HTTPError as e:<br> # list of error codes at http://docs.python.org/2/howto/urllib2.html<br> print('The server couldn\'t fulfill the request.')<br> print('Error code: ', e.code, responses[e.code])<br> print urllib2.info()<br>except urllib2.URLError as
e:<br> print('We failed to reach a server.')<br> print('Reason: ', e.reason)<br>else:<br> # everything is fine<br> #overpass_response = open(overpass_request)<br> #print "apres open"<br> overpass_txt=overpass_response.read().decode('utf8')<br> overpass_response.close()<br> overpass_json = json.loads(overpass_txt)</div><div style="color: rgb(0, 0, 191); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: italic;"><br> print "dictionnary elements - we access and print each element of the list"<br> elements=overpass_json["elements"]<br> nb=0<br> for element in elements:<br>
nb+=1<br> print "\n",nb,"\t",element<br> print "\t"+element["type"]+", id="+str(element["id"])+", lat="+str(element["lat"])+", lon="+str(element["lon"])<br> if ("name" in element["tags"]):<br> print "\tname="+element["tags"]["name"]<br><br></div><div style="color: rgb(0, 0, 191); font-size: 13.3333px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: italic;"><br></div> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 10pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <hr size="1"> <font face="Arial" size="2"> <b><span
style="font-weight:bold;">De :</span></b> Phanindra Kuchipudi <phani.800@gmail.com><br> <b><span style="font-weight: bold;">À :</span></b> dev@openstreetmap.org <br> <b><span style="font-weight: bold;">Envoyé le :</span></b> Lundi 4 novembre 2013 0h26<br> <b><span style="font-weight: bold;">Objet :</span></b> [OSM-dev] Downloading OSM data<br> </font> </div> <div class="y_msg_container"><br><div id="yiv4186018370"><div dir="ltr">Hi,<div><br></div><div>I want to write a python script to download OSM data based on a given bounding box (implementing XAPI). </div><div>Can anyone help me how to develop this script, and also can you give information on any other scripts available for this downloading functionality?</div>
<div><br></div><div>Thanks,</div><div>Phani</div></div></div><br>_______________________________________________<br>dev mailing list<br><a ymailto="mailto:dev@openstreetmap.org" href="mailto:dev@openstreetmap.org">dev@openstreetmap.org</a><br><a href="https://lists.openstreetmap.org/listinfo/dev" target="_blank">https://lists.openstreetmap.org/listinfo/dev</a><br><br><br></div> </div> </div> </div></body></html>