Skip to content

Commit

Permalink
Ansitemp apparent
Browse files Browse the repository at this point in the history
  • Loading branch information
onewheelskyward committed Dec 19, 2019
1 parent 1855258 commit ee63def
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/lita/handlers/forecasts.rb
Expand Up @@ -141,24 +141,28 @@ def do_the_humidity_thing(forecast, chars, key) #, type, range_colors = nil)
end

def ansi_temp_forecast(forecast, hours = 24)
str, temperature_data = do_the_temp_thing(forecast, ansi_chars, hours)
str, temperature_data = do_the_temp_thing(forecast, 'temperature', ansi_chars, hours)
"#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
end

def ansi_temp_apparent_forecast(forecast, hours = 24)
str, temperature_data = do_the_temp_thing(forecast, 'apparentTemperature', ansi_chars, hours)
"#{hours} hr apparent temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
end

def ansi_windchill_forecast(forecast, hours = 24)
str, temperature_data = do_the_windchill_temp_thing(forecast, ansi_chars, hours)
"#{hours} hr windchill temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
end

def ascii_temp_forecast(forecast, hours = 24)
str, temperature_data = do_the_temp_thing(forecast, ascii_chars, hours)
str, temperature_data = do_the_temp_thing(forecast, 'temperature', ascii_chars, hours)
"#{hours} hr temps: #{get_temperature temperature_data.first.round(1)} |#{str}| #{get_temperature temperature_data.last.round(1)} Range: #{get_temperature temperature_data.min.round(1)} - #{get_temperature temperature_data.max.round(1)}"
end

def do_the_temp_thing(forecast, chars, hours)
def do_the_temp_thing(forecast, key, chars, hours)
temps = []
data = forecast['hourly']['data'].slice(0,hours - 1)
key = 'temperature'

data.each_with_index do |datum, index|
temps.push datum[key]
Expand Down Expand Up @@ -337,7 +341,7 @@ def do_the_sunset_thing(forecast)
end

def conditions(forecast)
temp_str, temps = do_the_temp_thing(forecast, ansi_chars, 8)
temp_str, temps = do_the_temp_thing(forecast, 'temperature', ansi_chars, 8)
wind_str, winds = do_the_wind_direction_thing(forecast, ansi_wind_arrows, 8)
rain_str, rains = do_the_rain_chance_thing(forecast, ansi_chars, 'precipProbability', config.colors, 15)

Expand Down
6 changes: 6 additions & 0 deletions lib/lita/handlers/irc_handlers.rb
Expand Up @@ -45,6 +45,12 @@ def handle_irc_ansitemp(response)
response.reply location.location_name + ' ' + ansi_temp_forecast(forecast)
end

def handle_irc_ansitempapparent(response)
location = geo_lookup(response.user, response.match_data[1])
forecast = get_forecast_io_results(response.user, location)
response.reply location.location_name + ' ' + ansi_temp_forecast(forecast)
end

def handle_irc_ansiwindchill(response)
location = geo_lookup(response.user, response.match_data[1])
forecast = get_forecast_io_results(response.user, location)
Expand Down
3 changes: 3 additions & 0 deletions lib/lita/handlers/onewheel_forecast_io.rb
Expand Up @@ -26,6 +26,9 @@ class OnewheelForecastIo < Handler
route(/^ansitemp\s*$/i, :handle_irc_ansitemp, command: true)
route(/^ansitemp\s+(.+)/i, :handle_irc_ansitemp, command: true,
help: {'!ansitemp [location]' => 'The 24h temperature scale for [location].'})
route(/^ansitempapparent\s*$/i, :handle_irc_ansitempapparent, command: true)
route(/^ansitempapparent\s+(.+)/i, :handle_irc_ansitempapparent, command: true,
help: {'!ansitemp [location]' => 'The 24h temperature scale for [location].'})
route(/^dailytemp\s*$/i, :handle_irc_daily_temp, command: true)
route(/^dailytemp\s+(.+)/i, :handle_irc_daily_temp, command: true,
help: { '!dailytemp [location]' => '48h temperature scale for [location].'})
Expand Down
2 changes: 1 addition & 1 deletion lita-onewheel-forecast-io.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = 'lita-onewheel-forecast-io'
spec.version = '1.13.0'
spec.version = '1.14.0'
spec.authors = ['Andrew Kreps']
spec.email = ['andrew.kreps@gmail.com']
spec.description = <<-EOS
Expand Down

0 comments on commit ee63def

Please sign in to comment.