Skip to content

Commit

Permalink
i can export data from daily_water_consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvek committed Aug 19, 2023
1 parent d9a33ad commit f96170d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions exporter/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

entrypoint = ENV['ENTRYPOINT']
db = SQLite3::Database.new ENV['DATABASE']
name = ENV['NAME'] || 'daily_power_consumption'

db.execute("SELECT ts,value FROM data WHERE name='daily_power_consumption' ORDER BY ts DESC LIMIT 1") do |row|
title = "#{row[1].to_i/1000.0} kW.h"
db.execute("SELECT ts,value,unit FROM data WHERE name='#{name}' and ts=strftime('%s','now', 'start of day', '-1 day') ORDER BY ts DESC LIMIT 1") do |row|
unit = row[2]
title = "#{row[1].to_i/1000.0} kW.h" if unit == "indice"
title = "#{row[1]} L" if unit == "liter"
response = HTTParty.get("#{entrypoint}?title=#{title}&timestamp=#{row[0]}")
puts response.body
end

0 comments on commit f96170d

Please sign in to comment.