Last active
January 23, 2018 07:39
-
-
Save mohitmun/3ca54b7da54c4985147ef477227a26e6 to your computer and use it in GitHub Desktop.
Script I used to compare my travel time when using uber vs publictransport (bus, train) Note: This code doesnt include using bus/train data. Used google location history to track public transport timings
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
| require 'json' | |
| token = YOUR_TOKEN | |
| cmd = "curl -H 'Authorization: Bearer #{token}' -H 'Accept-Language: en_US' -H 'Content-Type: application/json' 'https://api.uber.com/v1.2/history?limit=50'" | |
| res = `#{cmd}` | |
| b = JSON.parse(res) | |
| require 'csv' | |
| data = [["Request time", "Start time", "End time", "Distance", "Wait time", "Travel time", "Total time"]] | |
| b["history"].each do |item| | |
| rt = Time.at(item["request_time"]) | |
| rts = rt.strftime("%m/%d/%Y %I:%M%p") | |
| st = Time.at(item["start_time"]) | |
| sts = st.strftime("%m/%d/%Y %I:%M%p") | |
| et = Time.at(item["end_time"]) | |
| ets = et.strftime("%m/%d/%Y %I:%M%p") | |
| distance = item["distance"] | |
| data << [rts, sts, ets, distance, Time.at(st - rt).utc.strftime("%H:%M:%S"), Time.at(et - st).utc.strftime("%H:%M:%S"), Time.at(et - rt).utc.strftime("%H:%M:%S")] | |
| end | |
| CSV.open("ubervspt.csv", "wb") do |csv| | |
| data.each do |item| | |
| csv << item | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment