summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshersonb <brian.sherson@gmail.com>2014-09-28 20:05:53 -0700
committershersonb <brian.sherson@gmail.com>2014-09-28 20:05:53 -0700
commit92af71570ab35143c8edab7f45520408751bf3c6 (patch)
tree067e3a45cdfb3009ef7723a048137814c8acd656
parentb5ec97e617d71ca1e7703b8492285246971efbc3 (diff)
parente0fac4c6408b8fd95f4c36f3fcaabefc257362ca (diff)
Merge pull request #2 from jesterpm/masterHEADmaster
Adding temperature conversion bot
-rw-r--r--tempconvertionbot.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tempconvertionbot.py b/tempconvertionbot.py
new file mode 100644
index 0000000..ca845c2
--- /dev/null
+++ b/tempconvertionbot.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+import os
+import re
+import time
+
+
+class TempConvertionBot(object):
+ def __init__(self, expiry=1800):
+ self.__name__ = "TempConversion Bot"
+ self.__version__ = "0.0.1"
+ self.pattern = re.compile(r"([-+]?\d+|[-+]?\d*\.\d+)\s*(?:degrees?)?\s*(C|F)(?=\s|$)")
+
+ def onChanMsg(self, IRC, user, channel, targetprefix, msg):
+ matches = self.pattern.findall(msg)
+ for quantity, unit in matches:
+ quantity = float(quantity)
+ if unit == 'C':
+ quantityPrime = quantity * 9 / 5.0 + 32
+ unitPrime = 'F'
+
+ elif unit == 'F':
+ quantityPrime = (quantity - 32) * 5 / 9.0
+ unitPrime = 'C'
+
+ channel.me("notes that %0.2f %s is %0.2f %s" % (quantity, unit, quantityPrime, unitPrime))