Created
July 12, 2009 19:07
-
-
Save erithmetic/145767 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Script to import data from mymilemarker.com mpg data to the Road Trip fuel economy tracking app | |
# Steps for OS X users: | |
# 1. Download this file to your user directory | |
# 2. Log into mymilemarker.com | |
# 3. Go to http://mymilemarker.com/vehicles/car-name/histories.xml?all=1 | |
# 4. Download the XMl file to histories.xml.colloquytranscript.xml in your home directory | |
# 5. Open Terminal app | |
# 6. type "gem install hpricot" | |
# 7. type "ruby fuel.rb" | |
# 8. type "cat history.csv | pbcopy" | |
# 9. Go to http://darrensoft.ca/roadtrip/csvimport/index.html and follow the instructions, | |
# pasting your data into the text area (the data will be in your clipboard) | |
require 'hpricot' | |
require 'date' | |
xml = File.read('histories.xml.colloquytranscript.xml') | |
doc = Hpricot(xml) | |
records = [] | |
(doc/'histories/history').each do |history| | |
values = [] | |
values << 'fuel' | |
values << (history/'mileage').text | |
date = Date.parse((history/'created-at').text) | |
values << date.strftime("%Y/%m/%d") | |
values << (history/'local-gallons').text | |
values << 'Gal' | |
values << (history/'price').text | |
values << ((history/'price').text.to_f * (history/'local-gallons').text.to_f) | |
values << 'Full' | |
fueleco = (history/'local-fuel-economy') | |
values << ((history/"fuel-economy[@nil=true]").empty? ? fueleco.text : nil) | |
values << '' << 86 << nil << nil << nil << nil << nil | |
records << values | |
end | |
records.each_with_index do |rec, i| | |
if rec[8].nil? | |
records[i - 1][16] = 1 | |
end | |
end | |
f = File.open('history.csv','w') | |
f.puts "Type,Odometer,Date,Fill Amount,Fill Units,Price per Unit,Total Price,Full Tank,MPG (US),Note,Octane,Location,Payment,Conditions,Description,Reset Stats" | |
records.each do |rec| | |
f.puts rec.join(',') | |
end | |
f.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment