Skip to content

Instantly share code, notes, and snippets.

Created Jun 15, 2012
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 = "RunKeeper.sqlite" )
db.execute( "select trip_id,start_date from trips" ) do |trip|
output= <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="" xmlns:gpsies="" creator="GPSies - 2012-06-101917" version="1.1" xmlns:xsi="" xsi:schemaLocation="">
<link href="">
<text>2012-06-101917 on</text>
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>"
output << "</trkseg></trk></gpx>"
#puts output
file="#{trip[0]}.gpx", "w") # the time will be the filename

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 =[3]/1000).iso8601()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment