blob: ca845c25b261055f626297166b1b24541483fd46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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))
|