Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: ebdfc5dc71
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (32 sloc) 1.752 kB
require 'rubygems'
require 'geoloqi'
require 'hashie'
require 'ffi'
require 'ffi-geos'
require 'sqlite3'
geoloqi = Geoloqi::Session.new :access_token => '3e8-3c900cebb9494ca52ed973ed126f3c1dfa81081d'
wkt_reader = Geos::WktReader.new
wkb_writer = Geos::WkbWriter.new
db = SQLite3::Database.new('history.sqlite')
db.execute("CREATE TABLE IF NOT EXISTS 'history' (OGC_FID INTEGER PRIMARY KEY AUTOINCREMENT, GEOMETRY BLOB, 'year' INTEGER, 'month' INTEGER, 'dayofweek' INTEGER, 'hour' INTEGER)")
db.execute('PRAGMA synchronous = OFF')
batch = 1000
startDate = DateTime.new 2010, 06, 01, 0, 0, 0, -0.00555555556
# DateTime.new(year, month, day, hour, min, seconds, offset)
offset = Rational(-480, 60 * 60 * 24) # Convert a UTC offset measured in minutes to one measured in a fraction of a day.
lastDate = startDate.to_time.to_i
puts 'Retrieving next batch of points from: ' + lastDate.to_s
result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
history = JSON.parse(result.body)
begin
history['points'].each do |p|
puts p['date']
point = wkt_reader.read 'POINT(' + p['location']['position']['longitude'].to_s + ' ' + p['location']['position']['latitude'].to_s + ')'
date = Time.at(p['date_ts'])
db.execute('INSERT INTO history (GEOMETRY, year, month, dayofweek, hour) VALUES (?,?,?,?,?)', SQLite3::Blob.new(wkb_writer.write point), date.year, date.month, date.wday, date.hour)
lastDate = p['date']
end
puts 'Retrieving next batch of points from: ' + lastDate.to_s
result = geoloqi.execute 'get'.to_sym, 'location/history?count=' + batch.to_s + '&sort=asc&after=' + lastDate.to_s
history = JSON.parse(result.body)
end while history['points'].length > 0
Jump to Line
Something went wrong with that request. Please try again.