Compare commits

..

No commits in common. "7615c6e892b50b4315fc6354b8b72c8ec388ffba" and "5a1e6c78a937dcea3ff8863c2a69e8e34f4c4f78" have entirely different histories.

2 changed files with 178 additions and 182 deletions

View file

@ -10,7 +10,3 @@ Layout/IndentationWidth:
Enabled: false Enabled: false
Layout/FirstArgumentIndentation: Layout/FirstArgumentIndentation:
Enabled: false Enabled: false
Layout/LineLength:
Enabled: false
Metrics/BlockLength:
Enabled: false

80
main.rb
View file

@ -11,7 +11,7 @@ options = {
:user_name => ENV['SMTP_UNAME'], :user_name => ENV['SMTP_UNAME'],
:password => ENV['SMTP_PWORD'], :password => ENV['SMTP_PWORD'],
:authentication => :plain, # :plain, :login, :cram_md5, no auth by default :authentication => :plain, # :plain, :login, :cram_md5, no auth by default
:domain => ENV['SMTP_DOMAIN'] # the HELO domain provided by the client to the server :domain => ENV['SMTP_DOMAIN'], # the HELO domain provided by the client to the server
} }
begin begin
@ -22,10 +22,9 @@ begin
password: ENV['MARIA_PWORD'], password: ENV['MARIA_PWORD'],
database: ENV['MARIA_DBASE'] database: ENV['MARIA_DBASE']
) )
puts "Successfully connected to MariaDB!"
puts 'Successfully connected to MariaDB!' puts "Compiling data..."
puts 'Compiling data...'
results_today = client.query(%( results_today = client.query(%(
SELECT LogDateTime, temp, dew, hum, rrate, rmonth, ryear SELECT LogDateTime, temp, dew, hum, rrate, rmonth, ryear
FROM Realtime FROM Realtime
@ -86,59 +85,59 @@ begin
# Max Temp # Max Temp
if result['temp'] >= maxmin[:temp][:max][:value] if result['temp'] >= maxmin[:temp][:max][:value]
maxmin[:temp][:max][:value] = result['temp'].to_f maxmin[:temp][:max][:value] = result['temp'].to_f
maxmin[:temp][:max][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:temp][:max][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Min Temp # Min Temp
if result['temp'] <= maxmin[:temp][:min][:value] if result['temp'] <= maxmin[:temp][:min][:value]
maxmin[:temp][:min][:value] = result['temp'].to_f maxmin[:temp][:min][:value] = result['temp'].to_f
maxmin[:temp][:min][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:temp][:min][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Max Dew Point # Max Dew Point
if result['dew'] >= maxmin[:dew][:max][:value] if result['dew'] >= maxmin[:dew][:max][:value]
maxmin[:dew][:max][:value] = result['dew'].to_f maxmin[:dew][:max][:value] = result['dew'].to_f
maxmin[:dew][:max][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:dew][:max][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Min Dew Point # Min Dew Point
if result['dew'] <= maxmin[:dew][:min][:value] if result['dew'] <= maxmin[:dew][:min][:value]
maxmin[:dew][:min][:value] = result['dew'].to_f maxmin[:dew][:min][:value] = result['dew'].to_f
maxmin[:dew][:min][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:dew][:min][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Max Humidity # Max Humidity
if result['hum'] >= maxmin[:hum][:max][:value] if result['hum'] >= maxmin[:hum][:max][:value]
maxmin[:hum][:max][:value] = result['hum'] maxmin[:hum][:max][:value] = result['hum']
maxmin[:hum][:max][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:hum][:max][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Min Humidity # Min Humidity
if result['hum'] <= maxmin[:hum][:min][:value] if result['hum'] <= maxmin[:hum][:min][:value]
maxmin[:hum][:min][:value] = result['hum'] maxmin[:hum][:min][:value] = result['hum']
maxmin[:hum][:min][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:hum][:min][:time] = result['LogDateTime'].strftime("%H:%M")
end end
# Max Rain Rate # Max Rain Rate
if result['rrate'] >= maxmin[:rainrate][:max][:value] if result['rrate'] >= maxmin[:rainrate][:max][:value]
maxmin[:rainrate][:max][:value] = result['rrate'].to_f maxmin[:rainrate][:max][:value] = result['rrate'].to_f
maxmin[:rainrate][:max][:time] = result['LogDateTime'].strftime('%H:%M') maxmin[:rainrate][:max][:time] = result['LogDateTime'].strftime("%H:%M")
end end
end end
puts 'Data compiled!' puts "Data compiled!"
puts 'Generating e-mail body...' puts "Generating e-mail body..."
table = Terminal::Table.new :title => "Weather Summary as of #{now['LogDateTime'].strftime('%l:%M %p, %a %b %d %Y')}" do |t| table = Terminal::Table.new :title => "Weather Summary as of #{now["LogDateTime"].strftime("%l:%M %p, %a %b %d %Y")}" do |t|
t << [ t << [
{ :value => 'Temperature', :colspan => 2, :alignment => :center }, { :value => "Temperature", :colspan => 2, :alignment => :center},
{ :value => 'Dew Point', :colspan => 2, :alignment => :center } { :value => "Dew Point", :colspan => 2, :alignment => :center}
] ]
t << :separator t << :separator
t << [ t << [
'Current', "#{now['temp'].to_s('F')}C", "Current", "#{now["temp"].to_s("F")}C",
'Current', "#{now['dew'].to_s('F')}C" "Current", "#{now["dew"].to_s("F")}C"
] ]
t << [ t << [
"Today's High", "#{maxmin[:temp][:max][:value]}C at #{maxmin[:temp][:max][:time]}", "Today's High", "#{maxmin[:temp][:max][:value]}C at #{maxmin[:temp][:max][:time]}",
@ -150,53 +149,53 @@ begin
] ]
t << :separator t << :separator
t << [ t << [
{ :value => 'Humidity', :colspan => 2, :alignment => :center }, { :value => "Humidity", :colspan => 2, :alignment => :center},
{ :value => 'Barometric Pressure (SL)', :colspan => 2, :alignment => :center } { :value => "Barometric Pressure (SL)", :colspan => 2, :alignment => :center}
] ]
t << :separator t << :separator
t << [ t << [
'Current', "#{now['hum']}%", "Current", "#{now["hum"]}%",
'Current', "#{now['press'].to_s('F')} mb" "Current", "#{now["press"].to_s("F")} mb"
] ]
t << [ t << [
"Today's High", "#{maxmin[:hum][:max][:value]}% at #{maxmin[:hum][:max][:time]}", "Today's High", "#{maxmin[:hum][:max][:value]}% at #{maxmin[:hum][:max][:time]}",
'Trend', "#{now['presstrendval']} mb/hr" "Trend", "#{now["presstrendval"]} mb/hr"
] ]
t << [ t << [
"Today's Low", "#{maxmin[:hum][:min][:value]}% at #{maxmin[:hum][:min][:time]}", "Today's Low", "#{maxmin[:hum][:min][:value]}% at #{maxmin[:hum][:min][:time]}",
'', '' "",""
] ]
t << :separator t << :separator
t << [ t << [
{ :value => 'Rain', :colspan => 2, :alignment => :center }, { :value => "Rain", :colspan => 2, :alignment => :center},
{ :value => 'Wind', :colspan => 2, :alignment => :center } { :value => "Wind", :colspan => 2, :alignment => :center}
] ]
t << :separator t << :separator
t << [ t << [
'Current Rate', "#{now['rrate']} #{now['rainunit']}/hr", "Current Rate", "#{now["rrate"]} #{now["rainunit"]}",
'Current Speed', "#{now['wspeed']} #{now['windunit']}" "Current Speed", "#{now["wspeed"].to_s} #{now["windunit"]}"
] ]
t << [ t << [
"Today's High Rate", "#{maxmin[:rainrate][:max][:value]} #{now['rainunit']} at #{maxmin[:rainrate][:max][:time]}", "Today's High Rate", "#{maxmin[:rainrate][:max][:value]} #{now["rainunit"]} at #{maxmin[:rainrate][:max][:time]}",
'Gust', "#{now['wgust']} #{now['windunit']}" "Gust", "#{now["wgust"].to_s} #{now["windunit"]}"
] ]
t << [ t << [
"Today's Total", "#{now['rfall'].to_s('F')} #{now['rainunit']}", "Today's Total", "#{now["rfall"].to_s("F")} #{now["rainunit"]}",
"Today's High Speed", "#{now['windTM']} #{now['windunit']} at #{now['TwindTM']}" "Today's High Speed", "#{now["windTM"].to_s} #{now["windunit"]} at #{now["TwindTM"]}"
] ]
t << [ t << [
'Monthly Total', "#{today['rmonth'].to_s('F')} #{now['rainunit']}", "Monthly Total","#{today["rmonth"].to_s("F")} #{now["rainunit"]}",
"Today's High Gust", "#{now['wgustTM']} #{now['windunit']} at #{now['TwgustTM']}" "Today's High Gust", "#{now["wgustTM"]} #{now["windunit"]} at #{now["TwgustTM"]}"
] ]
t << [ t << [
'Yearly Total', "#{today['ryear'].to_s('F')} #{now['rainunit']}", "Yearly Total","#{today["ryear"].to_s("F")} #{now["rainunit"]}",
'', '' "", ""
] ]
end end
puts 'E-mail body generated!' puts "E-mail body generated!"
puts 'Sending e-mail...' puts "Sending e-mail..."
Pony.mail( Pony.mail(
:to => ENV['MAIL_RECIPIENT'], :to => ENV['MAIL_RECIPIENT'],
@ -207,8 +206,9 @@ begin
:via_options => options :via_options => options
) )
puts 'E-mail sent!' puts "E-mail sent!"
puts 'DONE!' puts "DONE!"
rescue Mysql2::Error => e rescue Mysql2::Error => e
puts "Error connecting to database: #{e.message}" puts "Error connecting to database: #{e.message}"
ensure ensure