weather module. same output as in the irssi bot script. uses pywapi that was added a couple commits ago
This commit is contained in:
parent
c88b83a048
commit
d561d16e64
1
TODO
1
TODO
|
@ -3,7 +3,6 @@ dr.botzo --- TODO
|
||||||
Both a reminder to myself and a hint to anyone else who wants to hack around...
|
Both a reminder to myself and a hint to anyone else who wants to hack around...
|
||||||
|
|
||||||
* ALICE integration
|
* ALICE integration
|
||||||
* weather module
|
|
||||||
* 8ball style module
|
* 8ball style module
|
||||||
* modularizing
|
* modularizing
|
||||||
* commands (in IrcAdmin?) to allow for loading/unloading of modules and saving the config file
|
* commands (in IrcAdmin?) to allow for loading/unloading of modules and saving the config file
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
# coding: utf-8
|
||||||
|
"""
|
||||||
|
Weather - query various weather services for info
|
||||||
|
Copyright (C) 2010 Brian S. Stephan
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from extlib import irclib
|
||||||
|
from extlib import pywapi
|
||||||
|
|
||||||
|
from Module import Module
|
||||||
|
|
||||||
|
class Weather(Module):
|
||||||
|
"""Provide weather lookup services to the bot."""
|
||||||
|
|
||||||
|
def do(self, connection, event, nick, userhost, replypath, what, admin_unlocked):
|
||||||
|
"""Query Google Weather for a location's weather."""
|
||||||
|
|
||||||
|
whats = what.split(' ')
|
||||||
|
if whats[0] == "weather" and len(whats) >= 2:
|
||||||
|
try:
|
||||||
|
google_weather = pywapi.get_weather_from_google(''.join(whats[1:]))
|
||||||
|
weatherstr = "Current weather for " + google_weather['forecast_information']['city'].encode('utf-8') + ": " + google_weather['current_conditions']['condition'].encode('utf-8') + ". " + google_weather['current_conditions']['temp_f'].encode('utf-8') + "°F (" + google_weather['current_conditions']['temp_c'].encode('utf-8') + "°C), " + google_weather['current_conditions']['wind_condition'].encode('utf-8') + ", " + google_weather['current_conditions']['humidity'].encode('utf-8') + "."
|
||||||
|
|
||||||
|
for city in google_weather['forecasts']:
|
||||||
|
weatherstr += " " + city['day_of_week'].encode('utf-8') + ": " + city['condition'].encode('utf-8') + ". High " + city['high'].encode('utf-8') + "°F, Low " + city['low'].encode('utf-8') + "°F."
|
||||||
|
|
||||||
|
return self.reply(connection, replypath, unicode(weatherstr, 'utf-8'))
|
||||||
|
except IndexError as e:
|
||||||
|
print("error in pywapi: " + str(e))
|
||||||
|
return
|
||||||
|
|
||||||
|
# vi:tabstop=4:expandtab:autoindent
|
||||||
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
Loading…
Reference in New Issue