Created
August 15, 2010 09:08
-
-
Save bemasher/525279 to your computer and use it in GitHub Desktop.
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
import urllib2, json, re | |
raw = open("data.txt").read() #[\w\d]{2}:[\w\d]{2}:[\w\d]{2}:[\w\d]{2}:[\w\d]{2} | |
parse = re.compile("\t(.*?)\s((?:[\w\d]{2}:?){6}).*?(-\d+\s*dBm)\s*(-\d+\s*dBm)") | |
kml = open("data.kml", "w") | |
#"signal_strength": 8, "request_address": true, | |
request = '{"version": "1.1.0","host": "maps.google.com","address_language": "en_US", "wifi_towers": [{"mac_address": "%s","age": 0}]}' | |
kmlHead = '<?xml version="1.0" encoding="UTF-8"?>\n<kml xmlns="http://www.opengis.net/kml/2.2">\n<Folder>\n' | |
kmlBody = '<Placemark>\n<name>%s</name>\n<description>%s</description>\n<Point><coordinates>%f,%f,0</coordinates></Point>\n</Placemark>\n' | |
kmlTail = '</Folder>\n</kml>' | |
kml.write(kmlHead) | |
for bsid, addr, noise, quality in parse.findall(raw): | |
response = urllib2.urlopen("http://www.google.com/loc/json", data=request % (addr)).read() | |
data = json.loads(response) | |
name = "BSID: %s" % (bsid) | |
longitude = data["location"]["longitude"] | |
latitude = data["location"]["latitude"] | |
description = "MAC: %s\tNoise: %s\tQuality: %s" % (addr, noise, quality) | |
kml.write(kmlBody % (name, description, longitude, latitude)) | |
kml.write(kmlTail) | |
kml.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment