Skip to content

Instantly share code, notes, and snippets.

@kd35a
Created June 10, 2013 22:48
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 kd35a/5753134 to your computer and use it in GitHub Desktop.
Save kd35a/5753134 to your computer and use it in GitHub Desktop.
Background: Had the problem that I accidentally restarted my phone before saving my track I had recorded with RunKeeper. Shit. So I started to get as much data out of my phone as possible. And this is my story.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2013 Fredrik Strandin
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
# Background: Had the problem that I accidentally restarted my phone
# before saving my track I had recorded with RunKeeper. Shit. So I
# started to get as much data out of my phone as possible. And this is
# my story.
#
# $ adb backup -f /tmp/data.ab -noapk com.fitnesskeeper.runkeeper.pro
# $ cd /tmp
# $ dd if=data.ab bs=1 skip=24 | openssl zlib -d | tar -xvf -
# $ cd apps/com.fitnesskeeper.runkeeper.pro/db
# $ /path/to/extractor.py
# $$$ EPIC WIN $$$
import gpxpy
import gpxpy.gpx
import pytz
import sqlite3
from dateutil import tz
from datetime import datetime
LATITUDE = 4
LONGITUDE = 5
UNIXTIMESTAMP = 7
conn = sqlite3.connect('RunKeeper.sqlite')
c = conn.cursor()
data = c.execute('SELECT * FROM points WHERE trip_id = 3')
rows = data.fetchall()
gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
gpx_seg = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_seg)
for row in rows:
gpx_seg.points.append(gpxpy.gpx.GPXTrackPoint(
row[LATITUDE],
row[LONGITUDE],
time = datetime
.fromtimestamp(row[UNIXTIMESTAMP]//1000, tz.tzlocal())
.replace(microsecond=row[UNIXTIMESTAMP]%1000*1000)
.astimezone(pytz.utc)
)
)
gpx_file = open('my_track.gpx', 'w')
gpx_file.write(gpx.to_xml())
gpx_file.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment