Adds date parameter to report_mailer
This commit is contained in:
@@ -18,25 +18,25 @@ class ReadingsMailer
|
|||||||
# Class methods
|
# Class methods
|
||||||
#
|
#
|
||||||
class << self
|
class << self
|
||||||
def deliver
|
def deliver(date)
|
||||||
# Read SMTP options from smtp.yml
|
# Read SMTP options from smtp.yml
|
||||||
smtp_opts = YAML::load(File.open('config/smtp.yml')).symbolize_keys
|
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")
|
smtp_opts.merge!(SSL_OPTS) if smtp_opts[:ssl] && smtp_opts[:ssl_verify_mode].eql?("none")
|
||||||
|
|
||||||
# Fetch today's usage
|
# Fetch today's usage
|
||||||
usage_today = Reading.diff_on(Date.today)
|
usage_today = Reading.diff_on(date)
|
||||||
c = Cost.new
|
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])
|
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.today) # side effect: generates a PNG
|
easy_cost = c.easy_energy_cost_barplot(date) # side effect: generates a PNG
|
||||||
|
|
||||||
mail = Mail.new do
|
mail = Mail.new do
|
||||||
delivery_method :smtp, smtp_opts
|
delivery_method :smtp, smtp_opts
|
||||||
to 'a.t.van.halteren@vu.nl'
|
to 'a.t.van.halteren@vu.nl'
|
||||||
from 'SmartMeter <aart@van-halteren.net>'
|
from 'SmartMeter <aart@van-halteren.net>'
|
||||||
subject "SmartMeter report for #{Date.today}"
|
subject "SmartMeter report for #{date}"
|
||||||
|
|
||||||
text_part do
|
text_part do
|
||||||
body "Summary for #{Date.today}\n
|
body "Summary for #{date}\n
|
||||||
-------------------------------\n\n
|
-------------------------------\n\n
|
||||||
Total kWH electricity consumed: #{usage_today[:total_kwh_consumed_high] + usage_today[:total_kwh_consumed_low]}\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
|
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
|
html_part do
|
||||||
content_type 'text/html; charset=UTF-8'
|
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 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 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>" +
|
"<p>Total m3 gas consumed: #{usage_today[:total_m3_gas_consumed]}</p>" +
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ connection_details = YAML::load(File.open('config/database.yml'))
|
|||||||
ActiveRecord::Base.establish_connection(connection_details)
|
ActiveRecord::Base.establish_connection(connection_details)
|
||||||
|
|
||||||
if __FILE__ == $0
|
if __FILE__ == $0
|
||||||
ReadingsMailer.deliver
|
ReadingsMailer.deliver(Date.today)
|
||||||
end
|
end
|
||||||
#p sync
|
#p sync
|
||||||
|
|||||||
Reference in New Issue
Block a user