Created
May 4, 2009 07:17
-
-
Save wezm/106352 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'hpricot' | |
require 'time' | |
if ARGV.size < 1 | |
puts "Usage: fix_times.rb file.gpx" | |
exit 2 | |
end | |
File.open(ARGV[0]) do |f| | |
gpx = Hpricot.XML(f) | |
gpx.search('time').each do |time_elem| | |
time = Time.parse(time_elem.innerText) | |
new_time = time - (10 * 60 * 60) # 10 hours | |
puts "#{time.iso8601} => #{new_time.iso8601}" | |
time_elem.innerHTML = new_time.iso8601 | |
end | |
# Write out modified version | |
output_path = File.basename(f.path, File.extname(f.path)) + ' fixed' + File.extname(f.path) | |
File.open(output_path, 'w') do |ofile| | |
ofile.print gpx.to_s | |
end | |
puts "Fixed version written to #{output_path}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment