Skip to content

Instantly share code, notes, and snippets.

@jplattel
Last active December 21, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jplattel/6369894 to your computer and use it in GitHub Desktop.
Save jplattel/6369894 to your computer and use it in GitHub Desktop.
# Before using this script, you should have python installed. < http://python.org >
# For auth, go to http://web.kengao.tw/Untitled.php, and following the instruction of Moves.
# If done, you will see a line : your auth token : <a lot of characters>, just copy these characters
# download this .py file, and open it using text-editor
import requests
# paste your previously copied access token to replace the following ACCESS_TOKEN_TO_MOVES_APP
payload = {"access_token": "ACCESS_TOKEN_TO_MOVES_APP", "trackPoints":"true"}
def echo(loc, type, name):
if type is "point":
return """<Placemark>
<name>%s</name>
<Point>
<coordinates>%s, %s, 0</coordinates>
</Point>
</Placemark>"""%(name.encode("utf8"), loc["lon"], loc["lat"])
if type is "Line":
coordinates = ""
for i in loc:
coordinates = coordinates + "%s, %s, 0\n"%(i["lon"], i["lat"])
return """<Placemark>
<name>%s</name>
<LineString>
<extrude>1</extrude>
<tessellate>1</tessellate>
<altitudeMode>absolute</altitudeMode>
<coordinates> %s
</coordinates>
</LineString>
</Placemark>"""%(name.encode("utf8"), coordinates)
def renderxml( j, title, f ):
f.write("""<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Paths for %s</name>
<description></description>"""%title)
for i in j[0]["segments"]:
#print i
if i["type"] == "place":
if "name" not in i["place"]:
i["place"]["name"] = "unknown"
f.write(echo( i["place"]["location"], "point", i["place"]["name"] ))
if "activities" in i:
for k in i["activities"]:
r = []
for l in k["trackPoints"]:
r = r+[l]
f.write(echo( r, "Line", "move in %s"%i["place"]["name"]))
if i["type"] == "move":
if "activities" not in i:
continue
for k in i["activities"]:
r = []
for l in k["trackPoints"]:
r = r+[l]
f.write(echo( r, "Line", k["activity"]+" "+str(k["distance"]) ))
f.write(""" </Document>
</kml>""")
#enter the dates you want to export
datearray = ["20130613","20130614","20130615"]
# now you can save and close this file.
# open terminal / commend line tools, and cd to the folder the .py file is saved.
# enter the commend: python moves-kml.py
# the kml files will be stored on the same folder of the .py file
api = "https://api.moves-app.com/api/v1"
for date in datearray:
print date
r = requests.get(api+"/user/storyline/daily/"+date, params = payload)
j = r.json()
if j[0]["segments"] is None:
continue
f = open(date+".kml", "w")
renderxml(j, "date", f)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment