tfw: fix "sexy time" for 69°F

master
mutantmonkey 2013-09-30 22:40:03 -07:00
parent b8dde03000
commit 4edf618ef2
2 changed files with 47 additions and 25 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
""" """
test_tfw.py - tests for the fucking weather module test_tfw.py - tests for the fucking weather module
author: mutantmonkey <mutantmonkey@mutantmonkey.in> author: mutantmonkey <mutantmonkey@mutantmonkey.in>
@ -7,7 +8,7 @@ import re
import unittest import unittest
import tools import tools
from mock import MagicMock, Mock from mock import MagicMock, Mock
from modules.tfw import tfw from modules import tfw
class TestTfw(unittest.TestCase): class TestTfw(unittest.TestCase):
@ -16,34 +17,47 @@ class TestTfw(unittest.TestCase):
def test_badloc(self): def test_badloc(self):
input = Mock(group=lambda x: 'tu3jgoajgoahghqog') input = Mock(group=lambda x: 'tu3jgoajgoahghqog')
tfw(self.phenny, input) tfw.tfw(self.phenny, input)
self.phenny.say.assert_called_once_with( self.phenny.say.assert_called_once_with(
"WHERE THE FUCK IS THAT? Try another location.") "WHERE THE FUCK IS THAT? Try another location.")
def test_celsius(self): def test_celsius(self):
input = Mock(group=lambda x: '24060') input = Mock(group=lambda x: '24060')
tfw(self.phenny, input, celsius=True) tfw.tfw(self.phenny, input, celsius=True)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^\d+°C‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out, m = re.match('^\d+°C‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE) flags=re.UNICODE)
self.assertTrue(m) self.assertTrue(m)
def test_fahrenheit(self): def test_fahrenheit(self):
input = Mock(group=lambda x: '24060') input = Mock(group=lambda x: '24060')
tfw(self.phenny, input, fahrenheit=True) tfw.tfw(self.phenny, input, fahrenheit=True)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^\d+°F‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out, m = re.match('^\d+°F‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE) flags=re.UNICODE)
self.assertTrue(m) self.assertTrue(m)
def test_mev(self): def test_mev(self):
input = Mock(group=lambda x: '24060') input = Mock(group=lambda x: '24060')
tfw(self.phenny, input) tfw.tfw(self.phenny, input)
out = self.phenny.say.call_args[0][0] out = self.phenny.say.call_args[0][0]
m = re.match('^[\d\.]+ meV‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out, m = re.match('^[\d\.]+ meV‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE) flags=re.UNICODE)
self.assertTrue(m)
def test_sexy_time(self):
input = Mock(group=lambda x: 'KBCB')
tfw.web = MagicMock()
tfw.metar.parse = lambda x: Mock(temperature=21)
tfw.tfwf(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match(
r'^69°F‽ IT\'S FUCKING SEXY TIME \- .*',
out,
flags=re.UNICODE)
self.assertTrue(m) self.assertTrue(m)

View File

@ -11,6 +11,7 @@ import random
import metar import metar
import web import web
def tfw(phenny, input, fahrenheit=False, celsius=False): def tfw(phenny, input, fahrenheit=False, celsius=False):
""".tfw <city/zip> - Show the fucking weather at the specified location.""" """.tfw <city/zip> - Show the fucking weather at the specified location."""
@ -21,20 +22,20 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
else: else:
icao_code = weather.code(phenny, where) icao_code = weather.code(phenny, where)
if not icao_code: if not icao_code:
phenny.say("WHERE THE FUCK IS THAT? Try another location.") phenny.say("WHERE THE FUCK IS THAT? Try another location.")
return return
uri = 'http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT' uri = 'http://weather.noaa.gov/pub/data/observations/metar/stations/%s.TXT'
try: try:
bytes = web.get(uri % icao_code) bytes = web.get(uri % icao_code)
except AttributeError: except AttributeError:
raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.") raise GrumbleError("THE INTERNET IS FUCKING BROKEN. Please try again later.")
except web.HTTPError: except web.HTTPError:
phenny.say("WHERE THE FUCK IS THAT? Try another location.") phenny.say("WHERE THE FUCK IS THAT? Try another location.")
return return
if 'Not Found' in bytes: if 'Not Found' in bytes:
phenny.say("WHERE THE FUCK IS THAT? Try another location.") phenny.say("WHERE THE FUCK IS THAT? Try another location.")
return return
@ -52,7 +53,8 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
if w.temperature < 6: if w.temperature < 6:
remark = "IT'S FUCKING COLD" remark = "IT'S FUCKING COLD"
flavors = ["Where's the cat? Oh shit. Fluffy's frozen.", flavors = [
"Where's the cat? Oh shit. Fluffy's frozen.",
"Nothing a few shots couldn't fix", "Nothing a few shots couldn't fix",
"Should have gone south", "Should have gone south",
"You think this is cold? Have you been to upstate New York?", "You think this is cold? Have you been to upstate New York?",
@ -85,7 +87,8 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
"It's bone chilling cold out. Sorry ladies."] "It's bone chilling cold out. Sorry ladies."]
elif w.temperature < 20: elif w.temperature < 20:
remark = "IT'S FUCKING...ALRIGHT" remark = "IT'S FUCKING...ALRIGHT"
flavors = ["Might as well rain, I'm not going out in that.", flavors = [
"Might as well rain, I'm not going out in that.",
"Better than a sharp stick in the eye.", "Better than a sharp stick in the eye.",
"Everything's nice butter weather!", "Everything's nice butter weather!",
"At least you aren't living in a small town in Alaska", "At least you aren't living in a small town in Alaska",
@ -114,7 +117,8 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
"Maybe Jersey Shore is on tonight."] "Maybe Jersey Shore is on tonight."]
else: else:
remark = "IT'S FUCKING NICE" remark = "IT'S FUCKING NICE"
flavors = ["I made today breakfast in bed.", "FUCKING SWEET", flavors = [
"I made today breakfast in bed.", "FUCKING SWEET",
"Quit your bitching", "Enjoy.", "IT'S ABOUT FUCKING TIME", "Quit your bitching", "Enjoy.", "IT'S ABOUT FUCKING TIME",
"READ A FUCKIN' BOOK", "LETS HAVE A FUCKING PICNIC", "READ A FUCKIN' BOOK", "LETS HAVE A FUCKING PICNIC",
"It is safe to take your ball-mittens off.", "More please.", "It is safe to take your ball-mittens off.", "More please.",
@ -135,7 +139,7 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
"The geese are on their way back! Unless you live where they migrate to for the winter.", "The geese are on their way back! Unless you live where they migrate to for the winter.",
"FUCKING AFFABLE AS SHIT", "Give the sun a raise!", "FUCKING AFFABLE AS SHIT", "Give the sun a raise!",
"Today is better than an original holographic charizard. Loser!"] "Today is better than an original holographic charizard. Loser!"]
if w.descriptor == "thunderstorm": if w.descriptor == "thunderstorm":
remark += " AND THUNDERING" remark += " AND THUNDERING"
elif w.precipitation in ("snow", "snow grains"): elif w.precipitation in ("snow", "snow grains"):
@ -147,31 +151,35 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
elif w.precipitation in ("hail", "small hail"): elif w.precipitation in ("hail", "small hail"):
remark += " AND HAILING" remark += " AND HAILING"
if tempf == 69: if int(tempf) == 69:
remark = "IT'S FUCKING SEXY TIME" remark = "IT'S FUCKING SEXY TIME"
flavors = ["Why is 77 better than 69? You get eight more.", flavors = [
"What comes after 69? Mouthwash.", "Why is 77 better than 69? You get eight more.",
"If you are given two contradictory orders, obey them both.", "What comes after 69? Mouthwash.",
"a good fuckin' time! ;)", "If you are given two contradictory orders, obey them both.",
"What's the square root of 69? Eight something."] "a good fuckin' time! ;)",
"What's the square root of 69? Eight something."]
flavor = random.choice(flavors) flavor = random.choice(flavors)
response = "{temp} {remark} - {flavor} - {location} {time}Z".format( response = "{temp} {remark} - {flavor} - {location} {time}Z".format(
temp=temp, remark=remark, flavor=flavor, location=w.station, temp=temp, remark=remark, flavor=flavor, location=w.station,
time=w.time.strftime("%H:%M")) time=w.time.strftime("%H:%M"))
phenny.say(response) phenny.say(response)
tfw.rule = (['tfw'], r'(.*)') tfw.rule = (['tfw'], r'(.*)')
def tfwf(phenny, input): def tfwf(phenny, input):
""".tfwf <city/zip> - The fucking weather, in fucking degrees Fahrenheit.""" """.tfwf <city/zip> - The fucking weather, in fucking degrees Fahrenheit."""
return tfw(phenny, input, fahrenheit=True) return tfw(phenny, input, fahrenheit=True)
tfwf.rule = (['tfwf'], r'(.*)') tfwf.rule = (['tfwf'], r'(.*)')
def tfwc(phenny, input): def tfwc(phenny, input):
""".tfwc <city/zip> - The fucking weather, in fucking degrees celsius.""" """.tfwc <city/zip> - The fucking weather, in fucking degrees celsius."""
return tfw(phenny, input, celsius=True) return tfw(phenny, input, celsius=True)
tfwc.rule = (['tfwc'], r'(.*)') tfwc.rule = (['tfwc'], r'(.*)')
if __name__ == '__main__': if __name__ == '__main__':
print(__doc__.strip()) print(__doc__.strip())