Adds date parameter to report_mailer

This commit is contained in:
Aart van Halteren
2022-09-22 22:10:22 +02:00
parent 9587277c65
commit 719e59c1e5
2 changed files with 8 additions and 8 deletions

View File

@@ -18,25 +18,25 @@ class ReadingsMailer
# Class methods
#
class << self
def deliver
def deliver(date)
# Read SMTP options from smtp.yml
smtp_opts = YAML::load(File.open('config/smtp.yml')).symbolize_keys
smtp_opts.merge!(SSL_OPTS) if smtp_opts[:ssl] && smtp_opts[:ssl_verify_mode].eql?("none")
# Fetch today's usage
usage_today = Reading.diff_on(Date.today)
usage_today = Reading.diff_on(date)
c = Cost.new
oxxio_cost = c.oxxio_energy_cost(Date.today.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low])
easy_cost = c.easy_energy_cost_barplot(Date.today) # side effect: generates a PNG
oxxio_cost = c.oxxio_energy_cost(date.to_s,usage_today[:total_kwh_consumed_high]-usage_today[:total_kwh_produced_high], usage_today[:total_kwh_consumed_low]-usage_today[:total_kwh_produced_low])
easy_cost = c.easy_energy_cost_barplot(date) # side effect: generates a PNG
mail = Mail.new do
delivery_method :smtp, smtp_opts
to 'a.t.van.halteren@vu.nl'
from 'SmartMeter <aart@van-halteren.net>'
subject "SmartMeter report for #{Date.today}"
subject "SmartMeter report for #{date}"
text_part do
body "Summary for #{Date.today}\n
body "Summary for #{date}\n
-------------------------------\n\n
Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}\n
Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}\n
@@ -48,7 +48,7 @@ class ReadingsMailer
html_part do
content_type 'text/html; charset=UTF-8'
body "<h1>Summary for #{Date.today}</h1>" +
body "<h1>Summary for #{date}</h1>" +
"<p>Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}</p>" +
"<p>Total kWH electricity produced: #{usage_today[:total_kwh_produced_high] + usage_today[:total_kwh_produced_low]}</p>" +
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>" +