Skip to content

Instantly share code, notes, and snippets.

@aaronsherwood
Created August 10, 2013 03:19
Show Gist options
  • Save aaronsherwood/6198898 to your computer and use it in GitHub Desktop.
Save aaronsherwood/6198898 to your computer and use it in GitHub Desktop.
ruby script to get coordinates from openpaths and update a csv file with the info
#!/usr/bin/env ruby
require 'rubygems'
require 'httparty'
require 'crazylegs'
require 'json'
require 'FasterCSV'
include Crazylegs
index = []
time = []
FasterCSV.foreach("../coords.csv") do |row|
index.push(row[0])
time.push(row[3])
end
latestTime = Integer(time[-1])
latestTime+=1
consumer_key = "PUT KEY HERE"
consumer_secret = "PUT SECRET HERE"
base_url = "https://openpaths.cc/api/1"
credentials = Credentials.new(consumer_key,consumer_secret)
url = SignedURL.new(credentials, base_url,'GET')
@signed_url = url.full_url
@limit=@signed_url+'&num_points=2000' "&start_time=#{latestTime}"
@res = HTTParty.get(@limit)
@parsed = JSON.parse(@res.parsed_response)
count = Integer(index[-1])
FasterCSV.open("../coords.csv", "ab") do |csv|
for p in @parsed
count+=1
csv << [count, p["lat"], p["lon"], p["t"],p["alt"]]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment