Created
April 11, 2012 22:40
-
-
Save mibe/2363245 to your computer and use it in GitHub Desktop.
print'ing nearbyplace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
##import MySQLdb | |
import urllib2 | |
from xml.dom import minidom | |
##import db_config # DATABASE CONFIGURATION | |
values = {} | |
values["lat"] = 47.635 | |
values["lon"] = 16.7 | |
values["nearbyplace"] = "Unknown" | |
url = "http://ws.geonames.org/findNearbyPlaceName?lat=%s&lng=%s" % (values["lat"], values["lon"]) | |
try: | |
response = urllib2.urlopen(url) | |
except urllib2.URLError, e: | |
pass | |
else: | |
gnData = response.read() | |
dom = minidom.parseString(gnData) | |
if dom.getElementsByTagName('name'): | |
name = dom.getElementsByTagName('name')[0].firstChild.data | |
country = dom.getElementsByTagName('countryCode')[0].firstChild.data | |
values["nearbyplace"] = "%s [%s]" % (name, country) | |
print gnData | |
print values | |
print values["nearbyplace"] | |
##conn = MySQLdb.connect(db_config.host, user=db_config.user, passwd=db_config.password, db=db_config.dbname) | |
##cursor = conn.cursor() | |
##cursor.execute("INSERT INTO bugs SET lon = %(lon)s, nearby_place = %(nearbyplace)s", values) | |
##conn.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment