Added documentation and Celsius support to .tfw
parent
50b570f542
commit
f3c80c2ba7
|
@ -10,14 +10,21 @@ from urllib import quote as urlquote
|
||||||
from urllib2 import urlopen, HTTPError
|
from urllib2 import urlopen, HTTPError
|
||||||
import lxml.html
|
import lxml.html
|
||||||
|
|
||||||
def tfw(phenny, input):
|
def tfw(phenny, input, celsius=False):
|
||||||
|
""".tfw <city/zip> - Show the fucking weather at the specified location."""
|
||||||
|
|
||||||
zipcode = input.group(2)
|
zipcode = input.group(2)
|
||||||
if not zipcode:
|
if not zipcode:
|
||||||
# default to Blacksburg, VA
|
# default to Blacksburg, VA
|
||||||
zipcode = "24060"
|
zipcode = "24060"
|
||||||
|
|
||||||
|
if celsius:
|
||||||
|
celsius_param = "&CELSIUS=yes"
|
||||||
|
else:
|
||||||
|
celsius_param = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
req = urlopen("http://thefuckingweather.com/?zipcode=%s" % urlquote(zipcode))
|
req = urlopen("http://thefuckingweather.com/?zipcode=%s%s" % (urlquote(zipcode), celsius_param))
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
phenny.say("THE INTERNET IS FUCKING BROKEN. Please try again later.")
|
||||||
return
|
return
|
||||||
|
@ -51,6 +58,11 @@ def tfw(phenny, input):
|
||||||
phenny.say(response)
|
phenny.say(response)
|
||||||
tfw.rule = (['tfw'], r'(.*)')
|
tfw.rule = (['tfw'], r'(.*)')
|
||||||
|
|
||||||
|
def tfwc(phenny, input):
|
||||||
|
""".tfwc <city/zip> - The fucking weather, in fucking celsius."""
|
||||||
|
return tfw(phenny, input, True)
|
||||||
|
tfwc.rule = (['tfwc'], r'(.*)')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print __doc__.strip()
|
print __doc__.strip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue