latitude.py 961 B

12345678910111213141516171819202122232425
  1. import os
  2. import simplejson
  3. import subprocess
  4. import datetime
  5. f = open('latitude.json', 'r')
  6. locdata = simplejson.loads(f.read());
  7. fd = open('latitude.gpx', 'w')
  8. fd.write("""# <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
  9. <gpx xmlns="http://www.topografix.com/GPX/1/1"><trk><name>Google Latitude Export</name><trkseg>""")
  10. lastloc = None
  11. for value in reversed(sorted(locdata['data']['items'])):
  12. print value
  13. #raise Exception('def');
  14. if lastloc:
  15. timedelta = (int(value['timestampMs']) - int(lastloc['timestampMs'])) / 1000 / 60
  16. if timedelta > 10:
  17. # no points for 10 Minutes, Start new Track
  18. fd.write( "</trkseg><trkseg>")
  19. fd.write( '<trkpt lat="%s" lon="%s">' % (value['latitude'], value['longitude']))
  20. fd.write( '<time>%s</time></trkpt>' % str(datetime.datetime.fromtimestamp(int(value['timestampMs'])/1000)).replace(' ', 'T') + 'Z')
  21. lastloc = value
  22. fd.write( "</trkseg></trk></gpx>")