Skip to content

Commit

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

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 = "#{sprintf('%.2f', row[1])} °C" if unit == "temp"
title = "#{row[1]} L" if unit == "liter"
response = HTTParty.get("#{entrypoint}?title=#{title}&timestamp=#{row[0]}")
puts response.body
end

0 comments on commit 088ffc1

Please sign in to comment.