From 44354a590896916b51881f9987ef167947f8fbcf Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Mon, 6 Dec 2010 16:12:28 -0500 Subject: [PATCH] Added .tfw (The Fucking Weather) module --- modules/tfw.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 modules/tfw.py diff --git a/modules/tfw.py b/modules/tfw.py new file mode 100755 index 0000000..ce6314d --- /dev/null +++ b/modules/tfw.py @@ -0,0 +1,40 @@ +#!/usr/bin/python2 +""" +tfw.py - the fucking weather module +author: mutantmonkey +""" + +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
+ temp = main[0].text + + # parse comment (broken by
, 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() +