Merge pull request #52 from telnoratti/master

Added default support for meters.
master
mutantmonkey 2014-04-26 03:14:26 +00:00
commit b74d89eb5d
2 changed files with 19 additions and 4 deletions

View File

@ -42,13 +42,22 @@ class TestTfw(unittest.TestCase):
def test_mev(self):
input = Mock(group=lambda x: '24060')
tfw.tfw(self.phenny, input)
tfw.tfwev(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match('^[\-\d\.]+ meV‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE)
self.assertTrue(m)
def test_meter(self):
input = Mock(group=lambda x: '24060')
tfw.tfw(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match('^[\-\d\.]+ Meters‽ .* \- .* \- [A-Z]{4} \d{2}:\d{2}Z$', out,
flags=re.UNICODE)
self.assertTrue(m)
def test_sexy_time(self):
input = Mock(group=lambda x: 'KBCB')
tfw.web = MagicMock()

View File

@ -15,7 +15,7 @@ import metar
import web
def tfw(phenny, input, fahrenheit=False, celsius=False):
def tfw(phenny, input, fahrenheit=False, celsius=False, mev=False):
""".tfw <city/zip> - Show the fucking weather at the specified location."""
where = input.group(2)
@ -50,9 +50,11 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
temp = "{0:d}°F‽".format(int(tempf))
elif celsius:
temp = "{0:d}°C‽".format(w.temperature)
else:
elif mev:
tempev = (w.temperature + 273.15) * 8.617343e-5 * 1000
temp = "%f meV‽" % tempev
else:
temp = "{0:f} Meters‽".format((w.temperature + 273.15) * 8.617343e-5 * 12.39842)
if w.temperature < 6:
remark = "IT'S FUCKING COLD"
@ -192,7 +194,7 @@ def tfw(phenny, input, fahrenheit=False, celsius=False):
temp=temp, remark=remark, flavor=flavor, location=w.station,
time=w.time.strftime("%H:%M"))
phenny.say(response)
tfw.rule = (['tfw'], r'(.*)')
tfw.rule = (['tfw', 'tfwm'], r'(.*)')
def tfwf(phenny, input):
@ -206,6 +208,10 @@ def tfwc(phenny, input):
return tfw(phenny, input, celsius=True)
tfwc.rule = (['tfwc'], r'(.*)')
def tfwev(phenny, input):
""".tfwc <city/zip> - The fucking weather, in fucking degrees celsius."""
return tfw(phenny, input, mev=True)
tfwev.rule = (['tfwev'], r'(.*)')
if __name__ == '__main__':
print(__doc__.strip())