# Copyright (c) 2013-2014 Molly White
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import json
from plugins.util import admin, command, get_url

@command()
def weather(m):

    #-     !weather location
    #-
    #- ```irc
    #- < GorillaWarfare> !weather boston
    #- < GorillaBot> Weather in Boston, MA, USA: Mostly cloudy until tomorrow morning.
    #- ```
    #-
    #- Provide weather information for the given location.
    #-
    #- In order to provide weather information, you must provide a Forecast.io API key when
    #-  configuring the bot. You can get an API key by registering an email address at
    #-  http://developer.forecast.io/.

    api_key = m.bot.get_config('forecast')
    if api_key:
        m.bot.logger.info("Finding weather for {}.".format(" ".join(m.line[1:])))
        google_api = "http://maps.googleapis.com/maps/api/geocode/json?address={}"
        forecast_api = "https://api.forecast.io/forecast/{0}/{1},{2}?exclude=currently,minutely," \
                       "daily,alerts,flags"
        loc = "+".join(m.line[1:])
        resp = get_url(m, google_api.format(loc))
        blob = json.loads(resp)
        lat = blob['results'][0]['geometry']['location']['lat']
        long = blob['results'][0]['geometry']['location']['lng']
        addr = blob['results'][0]['formatted_address']
        resp = get_url(m, forecast_api.format(api_key, lat, long))
        blob = json.loads(resp)
        summary = blob['hourly']['summary']
        weather = "Weather in {0}: {1}".format(addr, summary)
        m.bot.private_message(m.location, weather)
    else:
        m.bot.logger.info("No Forecast.io API key recorded.")
@@ -1350,16 +1350,67 @@
 orning.%0A
+    #-               59%CB%9AF (15.0%CB%9AC). Humidity: 92%25.%0A
     #- %60
@@ -2528,60 +2528,326 @@
     
-weather = %22Weather in %7B0%7D: %7B1%7D%22.format(addr, summary
+temp = round(blob%5B'hourly'%5D%5B'data'%5D%5B0%5D%5B'temperature'%5D)%0A        humidity = round(blob%5B'hourly'%5D%5B'data'%5D%5B0%5D%5B'humidity'%5D * 100)%0A        print(temp)%0A        weather = %22Weather in %7B0%7D: %7B1%7D %7B2%7D%CB%9AF (%7B3%7D%CB%9AC). Humidity: %7B4%7D%25.%22%5C%0A            .format(addr, summary, str(temp), str((temp - 32)*5/9), str(humidity))%0A        print(blob
 )%0A  

Add temperature and humidity to weather plugin