From b9f0da7d74102483d86b2074e8427a40e6dc1c79 Mon Sep 17 00:00:00 2001 From: Calvin Winkowski Date: Fri, 25 Apr 2014 16:30:41 -0400 Subject: [PATCH 1/3] Added default support for meters. --- modules/tfw.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/tfw.py b/modules/tfw.py index 13eccef..130b301 100644 --- a/modules/tfw.py +++ b/modules/tfw.py @@ -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 - 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 - The fucking weather, in fucking degrees celsius.""" + return tfw(phenny, input, meV=True) +tfweV.rule = (['tfweV', 'tfwev'], r'(.*)') if __name__ == '__main__': print(__doc__.strip()) From 9248b6721c2cd19e84515c8d1a57792b6985081b Mon Sep 17 00:00:00 2001 From: Calvin Winkowski Date: Fri, 25 Apr 2014 17:15:33 -0400 Subject: [PATCH 2/3] Fixed the tests. --- modules/test/test_tfw.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/test/test_tfw.py b/modules/test/test_tfw.py index ebea00b..18c7621 100644 --- a/modules/test/test_tfw.py +++ b/modules/test/test_tfw.py @@ -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() From b73a04854111b03c8ae0a3b3767b4e280300a5af Mon Sep 17 00:00:00 2001 From: Telnoratti Date: Fri, 25 Apr 2014 20:27:50 -0400 Subject: [PATCH 3/3] Changed capitalization of eV. Even though Volt units are capitalized V, when you write code apparently conventions older than computers themselves are rejected in favour of newer conventions. --- modules/test/test_tfw.py | 2 +- modules/tfw.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/test/test_tfw.py b/modules/test/test_tfw.py index 18c7621..f1e9e8c 100644 --- a/modules/test/test_tfw.py +++ b/modules/test/test_tfw.py @@ -42,7 +42,7 @@ class TestTfw(unittest.TestCase): def test_mev(self): input = Mock(group=lambda x: '24060') - tfw.tfweV(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, diff --git a/modules/tfw.py b/modules/tfw.py index 130b301..8b2d891 100644 --- a/modules/tfw.py +++ b/modules/tfw.py @@ -15,7 +15,7 @@ import metar import web -def tfw(phenny, input, fahrenheit=False, celsius=False, meV=False): +def tfw(phenny, input, fahrenheit=False, celsius=False, mev=False): """.tfw - Show the fucking weather at the specified location.""" where = input.group(2) @@ -50,7 +50,7 @@ def tfw(phenny, input, fahrenheit=False, celsius=False, meV=False): temp = "{0:d}°F‽".format(int(tempf)) elif celsius: temp = "{0:d}°C‽".format(w.temperature) - elif meV: + elif mev: tempev = (w.temperature + 273.15) * 8.617343e-5 * 1000 temp = "%f meV‽" % tempev else: @@ -208,10 +208,10 @@ def tfwc(phenny, input): return tfw(phenny, input, celsius=True) tfwc.rule = (['tfwc'], r'(.*)') -def tfweV(phenny, input): +def tfwev(phenny, input): """.tfwc - The fucking weather, in fucking degrees celsius.""" - return tfw(phenny, input, meV=True) -tfweV.rule = (['tfweV', 'tfwev'], r'(.*)') + return tfw(phenny, input, mev=True) +tfwev.rule = (['tfwev'], r'(.*)') if __name__ == '__main__': print(__doc__.strip())