Permalink
Browse files

committed

  • Loading branch information...
0 parents commit 4a2ff949ae7d94fb936c3fd79b6157a8beb3d5db @kracekumar committed Feb 21, 2011
Showing with 24 additions and 0 deletions.
  1. +3 −0 README
  2. +21 −0 details.py
3 README
@@ -0,0 +1,3 @@
+run python details.py and enter the city name .
+Note:
+City name should be string and not number/zipcode
@@ -0,0 +1,21 @@
+#! /usr/bin/env python
+"""This script will get latitude longitude of a city along with country details"""
+import sys
+import urllib2
+from lxml import etree
+"""lxml will help us parsing the xml file returned by yahoo api"""
+app_id="dj0yJmk9SVlORFVHN1Fab0Z6JmQ9WVdrOWRWWXlVMWxaTldFbWNHbzlNVEkxTVRZNU5qVTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD01Nw"
+try:
+ city=str(raw_input("Please enter city name:"))
+ url="http://local.yahooapis.com/MapsService/V1/geocode?appid="+app_id+"&location="+city
+ conn=urllib2.urlopen(url)
+ root=etree.parse(conn)
+ print "city :"+city
+ print ("Latitude:%s"%(root.xpath("/m:ResultSet/m:Result/m:Latitude/text()", namespaces={"m": "urn:yahoo:maps"})))
+#fetching latitude
+ print ("Longitude:%s"%(root.xpath("/m:ResultSet/m:Result/m:Longitude/text()", namespaces={"m": "urn:yahoo:maps"})))
+ print ("City:%s"%(root.xpath("/m:ResultSet/m:Result/m:City/text()", namespaces={"m": "urn:yahoo:maps"})))
+ print ("Country:%s"%(root.xpath("/m:ResultSet/m:Result/m:State/text()", namespaces={"m": "urn:yahoo:maps"})))
+except ValueError:
+ print ("City name should be string ")
+ sys.exit()

0 comments on commit 4a2ff94

Please sign in to comment.