Created
June 15, 2012 15:45
-
-
Save moritzh/2937136 to your computer and use it in GitHub Desktop.
Script to read RunKeeper.sqlite files and convert the data to .gpx files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change line 16 to
remove the trailing
"
on line 28 and modify line 36 to