From 61da6801b956f1acbda133b8eb9ea15669e6110f Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Tue, 10 Jan 2017 20:13:25 -0500 Subject: [PATCH] Adding option to use fahrenheit temperature instead of celsius (#1) --- README.md | 6 ++++++ src/weather.coffee | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd2d7e5..656a98c 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ Then add **hubot-weather-underground** to your `external-scripts.json`: `HUBOT_WEATHER_WUNDERGROUND_KEY=YOUR_WUNDERGROUND_KEY` +## Temperature format + +If you want to use fahrenheit instead of celsius use the following environment variable + +`HUBOT_WEATHER_UNDERGROUND_FORMAT=F` + ## Sample Interaction ``` diff --git a/src/weather.coffee b/src/weather.coffee index 9130660..8eb6fa2 100644 --- a/src/weather.coffee +++ b/src/weather.coffee @@ -13,6 +13,8 @@ WUNDERGROUND_KEY = process.env.HUBOT_WEATHER_WUNDERGROUND_KEY +WUNDERGROUND_WEATHER_FORMAT = if process.env.HUBOT_WEATHER_WUNDERGROUND_FORMAT then process.env.HUBOT_WEATHER_WUNDERGROUND_FORMAT else 'c' + WUNDERGROUND_URL = "http://api.wunderground.com/api/#{WUNDERGROUND_KEY}" module.exports = (robot) -> @@ -29,11 +31,17 @@ module.exports = (robot) -> try data = JSON.parse(body) obs = data.current_observation + temp = obs.temp_f+'°C' + feels_like = obs.feelslike_f+'°C' + if WUNDERGROUND_WEATHER_FORMAT == 'f' + temp = obs.temp_c+'°F' + feels_like = obs.feelslike_c+'°F' + msg.send "The current weather condition of " + "#{obs.display_location.full} is #{obs.weather}:\n" + "#{obs.observation_time}, " + - "Temperature is #{obs.temp_c}°C " + - "(feels like #{obs.feelslike_c}°C), " + + "Temperature is #{temp} " + + "(feels like #{feels_like}), " + "Humidity #{obs.relative_humidity}, " + "Pressure #{obs.pressure_mb}hPa, " + "Wind #{obs.wind_string}, " +