Added .tfw (The Fucking Weather) module

master
mutantmonkey 2010-12-06 16:12:28 -05:00
parent bf8b638971
commit 44354a5908
1 changed files with 40 additions and 0 deletions

40
modules/tfw.py Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/python2
"""
tfw.py - the fucking weather module
author: mutantmonkey <mutantmonkey@gmail.com>
"""
import random
from urllib2 import urlopen
import lxml.html
def tfw(phenny, input):
zipcode = input.group(2)
zipcode = int(zipcode)
req = urlopen("http://thefuckingweather.com/?zipcode=%d" % zipcode)
doc = lxml.html.parse(req)
location = doc.getroot().find_class('small')[0].text_content()
weather = doc.getroot().get_element_by_id('content')
main = weather.find_class('large')
# temperature is everything up to first <br />
temp = main[0].text
# parse comment (broken by <br />, so we have do it this way)
comments = main[0].xpath('text()')
comment = "%s %s" % (comments[1], comments[2])
# remark is in its own div, so we have it easy
remark = weather.get_element_by_id('remark').text_content()
response = "%s %s - %s - %s" % (temp, comment, remark, location)
phenny.say(response)
tfw.rule = (['tfw'], r'(.*)')
if __name__ == '__main__':
print __doc__.strip()