Skip to content

Instantly share code, notes, and snippets.

@moritzh
Created Jun 15, 2012
Embed
What would you like to do?
Script to read RunKeeper.sqlite files and convert the data to .gpx files.
# Simple HowTo: Grab the Application PhoneView or something else to gather the "RunKeeper.sqlite" from your iPhone's RunKeeper Application Directory.
# Put it in the same directory as the "to_gpx.rb" script. simply run the to_gpx.rb script using
# ruby to_gpx.rb
# you should now have a collection of gpx files, numbered according to the internal trip_ids used by runkeeper. you can upload these gpx files to runkeeper.
# Requirements:
# - 'sqlite3-ruby'
require 'date'
require 'rubygems'
require 'sqlite3'
# open the db
db = SQLite3::Database.new( "RunKeeper.sqlite" )
db.execute( "select trip_id,start_date from trips" ) do |trip|
output= <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpsies="http://www.gpsies.com/GPX/1/0" creator="GPSies http://www.gpsies.com - 2012-06-101917" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.gpsies.com/GPX/1/0 http://www.gpsies.com/gpsies.xsd">
<metadata>
<name>2012-06-101917</name>
<link href="http://www.gpsies.com/">
<text>2012-06-101917 on GPSies.com</text>
</link>
<time>2012-06-10T20:39:08Z</time>
</metadata><trk><trkseg>"
EOF
db.execute("select latitude,longitude,altitude,time_at_point from points where trip_id = #{trip[0]};") do |components|
lat = components[0]
lon = components[1]
ele = components[2]
time = components[3]
output<< "<trkpt lat=\"#{lat}\" lon=\"#{lon}\"><ele>#{ele}</ele><time>#{time}</time></trkpt>"
end
output << "</trkseg></trk></gpx>"
#puts output
file= File.new("#{trip[0]}.gpx", "w") # the time will be the filename
file.write(output)
file.close
end
@kartikmohta

This comment has been minimized.

Copy link

@kartikmohta kartikmohta commented May 29, 2015

Change line 16 to

db.execute( "select _id,start_date from trips" ) do |trip|

remove the trailing " on line 28 and modify line 36 to

time = Time.at(components[3]/1000).iso8601()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment