Skip to content

Commit

Permalink
Adding option to use fahrenheit temperature instead of celsius (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kodemaan authored and kkpoon committed Jan 11, 2017
1 parent 38a372c commit 61da680
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
12 changes: 10 additions & 2 deletions src/weather.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand All @@ -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}, " +
Expand Down

0 comments on commit 61da680

Please sign in to comment.