Skip to content

Instantly share code, notes, and snippets.

@timdorr
Created November 14, 2013 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timdorr/7474641 to your computer and use it in GitHub Desktop.
Save timdorr/7474641 to your computer and use it in GitHub Desktop.
Stream data from Tesla's API to TempoDB
class TeslaStreamReader
def initialize(email, password)
@tesla_api = TeslaApi.new(email, password)
end
def stream_to_tempodb
loop do
@tesla_api.vehicles.first.wake_up
car = @tesla_api.vehicles.first
car.stream do |state|
data = []
state.except(:time).each do |key, value|
data << { key: key, v: value.to_f }
end
$tempodb.write_bulk(state[:time], data)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment