mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
Add Weather.rsswunder
This commit is contained in:
parent
32dce478c5
commit
e3b039b2e3
@ -56,7 +56,9 @@ import plugin
|
|||||||
reload(plugin) # In case we're being reloaded.
|
reload(plugin) # In case we're being reloaded.
|
||||||
# Add more reloads here if you add third-party modules and want them to be
|
# Add more reloads here if you add third-party modules and want them to be
|
||||||
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||||
|
import rssparser
|
||||||
import BeautifulSoup
|
import BeautifulSoup
|
||||||
|
reload(rssparser)
|
||||||
reload(BeautifulSoup)
|
reload(BeautifulSoup)
|
||||||
|
|
||||||
if world.testing:
|
if world.testing:
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import rssparser
|
||||||
import BeautifulSoup
|
import BeautifulSoup
|
||||||
|
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
@ -46,7 +47,7 @@ class NoLocation(callbacks.Error):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class Weather(callbacks.Plugin):
|
class Weather(callbacks.Plugin):
|
||||||
weatherCommands = ['wunder', 'cnn', 'ham']
|
weatherCommands = ['wunder', 'rsswunder', 'cnn', 'ham']
|
||||||
threaded = True
|
threaded = True
|
||||||
def __init__(self, irc):
|
def __init__(self, irc):
|
||||||
self.__parent = super(Weather, self)
|
self.__parent = super(Weather, self)
|
||||||
@ -438,6 +439,37 @@ class Weather(callbacks.Plugin):
|
|||||||
irc.error('Could not find weather information.')
|
irc.error('Could not find weather information.')
|
||||||
wunder = wrap(wunder, ['text'])
|
wunder = wrap(wunder, ['text'])
|
||||||
|
|
||||||
|
_rsswunderUrl = 'http://www.wunderground.com/cgi-bin/findweather/' \
|
||||||
|
'getForecast?query=%s'
|
||||||
|
_rsswunderfeed = re.compile(r'<link rel="alternate".*href="([^"]+)">',
|
||||||
|
re.I)
|
||||||
|
_rsswunderSevere = re.compile(r'font color="?#ff0000"?><b>([^<]+)<', re.I)
|
||||||
|
def rsswunder(self, irc, msg, args, loc):
|
||||||
|
"""<US zip code | US/Canada city, state | Foreign city, country>
|
||||||
|
|
||||||
|
Returns the approximate weather conditions for a given city.
|
||||||
|
"""
|
||||||
|
url = self._rsswunderUrl % utils.web.urlquote(loc)
|
||||||
|
url = url.replace('%20', '+')
|
||||||
|
text = utils.web.getUrl(url)
|
||||||
|
severe = ''
|
||||||
|
m = self._rsswunderSevere.search(text)
|
||||||
|
if m:
|
||||||
|
severe = ircutils.bold(m.group(1))
|
||||||
|
if 'Search not found' in text or \
|
||||||
|
re.search(r'size="2"> Place </font>', text, re.I):
|
||||||
|
self._noLocation()
|
||||||
|
feed = self._rsswunderfeed.search(text)
|
||||||
|
if not feed:
|
||||||
|
irc._noLocation()
|
||||||
|
feed = feed.group(1)
|
||||||
|
rss = utils.web.getUrl(feed)
|
||||||
|
info = rssparser.parse(rss)
|
||||||
|
resp = [e['summary'] for e in info['entries']]
|
||||||
|
resp = [s.encode('utf-8') for s in resp]
|
||||||
|
resp.append(severe)
|
||||||
|
irc.reply(utils.web.htmlToText('; '.join(resp)))
|
||||||
|
rsswunder = wrap(rsswunder, ['text'])
|
||||||
|
|
||||||
Class = Weather
|
Class = Weather
|
||||||
|
|
||||||
|
2571
plugins/Weather/rssparser.py
Normal file
2571
plugins/Weather/rssparser.py
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user