7
__copyright__ = 'this file is in the public domain'
10
from gozerbot.commands import cmnds
11
from gozerbot.examples import examples
12
from gozerbot.plughelp import plughelp
15
plughelp.add('convert', 'convert data')
19
def gallontoliter(num):
20
return 3.7854118 * num
22
def litertogallon(num):
23
return 1/3.7854118 * num
26
return 3.2808399 * num
29
return 1/3.2808399 * num
32
return 1/1.609344 * num
37
def celciustofahrenheit(num):
38
return 1.8 * num + 32.0
40
def fahrenheittocelcius(num):
41
return 0.5555555 * num + -17.7777777
43
def kelvintocelcius(num):
46
def celciustokelvin(num):
49
def fahrenheittokelvin(num):
50
return 0.5555 * num + -17.77777777 + 273.000
52
def kelvintofahrenheit(num):
53
return 1.8 * (num + 32.0) - 273.0
79
def eurotogulden(num):
82
def guldentoeuro(num):
83
return num * 1/2.20371
85
def handle_convert(bot, ievent):
86
""" convert <nuw> <unit> to <unit> .. convert data """
88
num = float(ievent.args[0])
89
from_unit = ievent.args[1]
90
if ievent.args[2] != 'to':
92
to_unit = ievent.args[3]
94
ievent.reply('convert <num> <unit> to <unit>')
97
func = getattr(sys.modules['gozerplugs.plugs.convert'], \
98
from_unit + 'to' + to_unit)
100
except (KeyError, AttributeError):
101
ievent.reply("sorry can't convert from %s to %s" % (from_unit, \
104
except Exception, ex:
105
ievent.reply('ERROR: %s' % str(ex))
107
ievent.reply('%s %s ==> %s %s' % (num, from_unit, result, to_unit))
109
cmnds.add('convert', handle_convert, 'USER')
110
examples.add('convert','convert <num> <unit> to <unit>', \
111
'convert 100 fahrenheit to celcius')
113
def handle_convertlist(bot, ievent):
114
""" convert-list .. show al available converter functions """
116
for i in dir(sys.modules['gozerplugs.plugs.convert']):
117
if i.startswith('__'):
119
if i in ('cmnds', 'examples', 'sys', 'plughelp'):
124
ievent.reply("available converts: ", res, dot=True)
126
cmnds.add('convert-list', handle_convertlist, 'USER')
127
examples.add('convert-list', 'list possible convertions', 'convert-list')