diff --git a/exporter/main.rb b/exporter/main.rb index 3ea3dd7..dd5ed25 100644 --- a/exporter/main.rb +++ b/exporter/main.rb @@ -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}×tamp=#{row[0]}") puts response.body end \ No newline at end of file