-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadAndChangeXML.py
More file actions
executable file
·36 lines (30 loc) · 921 Bytes
/
readAndChangeXML.py
File metadata and controls
executable file
·36 lines (30 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import xml.etree.cElementTree as ET
import urllib2
import json
import os
lastLat = ""
lastLng = ""
def getPokemonLocation():
try:
response = urllib2.urlopen("http://192.168.178.25/", timeout = 3)
return json.load(response)
except urllib2.URLError as e:
print e.reason
def generateXML():
global lastLat, lastLng
geo = getPokemonLocation()
if geo != None:
if geo["lat"] != lastLat or geo["lng"] != lastLng:
lastLat = geo["lat"]
lastLng = geo["lng"]
gpx = ET.Element("gpx", version="1.1", creator="Xcode")
wpt = ET.SubElement(gpx, "wpt", lat=geo["lat"], lon=geo["lng"])
ET.SubElement(wpt, "name").text = "PokemonLocation"
ET.ElementTree(gpx).write("PokemonLocation.gpx")
print "Location Updated!", "latitude:", geo["lat"], "longitude:" ,geo["lng"]
def start():
while True:
generateXML()
if os.path.isfile("click.applescript"):
os.system("osascript click.applescript")
start()