#!/usr/bin/env python3 # # Copyright (C) 2011 Thomas Jost # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. import datetime import sqlite3 import sys if len(sys.argv) < 2: print("Syntax: {0} path-to-consolidated.db > output.kml".format(sys.argv[0]), file=sys.stderr) sys.exit(1) conn = sqlite3.connect(sys.argv[1]) conn.row_factory = sqlite3.Row curs = conn.cursor() curs.execute("select * from celllocation") # KML header print(""" iPhone tracking 1 iPhone tracking data, directly extracted from a fresh "consolidated.db" database """) # KML data cur_ts = "" for row in curs: lat, lon, ts = row["Latitude"], row["Longitude"], row["Timestamp"] # Apple uses timestamps that store the number of seconds since 2001... dt = datetime.date.fromtimestamp(int(ts) + 978307200) iso_ts = dt.isoformat() human_ts = dt.strftime("%x") if cur_ts != "" and human_ts != cur_ts: print(""" """) if human_ts != cur_ts: cur_ts = human_ts print(""" Location on {0} {1} #transPurpleLineGreenPoly 1 1 """.format(human_ts, iso_ts)) print(" {0},{1}".format(lon, lat)) # KML footer print(""" """)