# HG changeset patch # User Santeri Piippo # Date 1404170194 -10800 # Node ID c25944cac3e6e307f853730e30cbbb5df5d79074 # Parent 3e2ce6056fb7dc3cc9aeeee661a23746bb835df4 - added .convert with angle and temperature conversions diff -r 3e2ce6056fb7 -r c25944cac3e6 cobalt.py --- a/cobalt.py Sun Jun 29 21:36:01 2014 +0000 +++ b/cobalt.py Tue Jul 01 02:16:34 2014 +0300 @@ -39,6 +39,7 @@ import hgapi import os import suds +import math try: uid = os.geteuid() @@ -532,11 +533,33 @@ elif command == 'die': check_admin (sender, ident, host, command) quit() - elif command == 'testlog': - check_admin (sender, ident, host, command) - if len(args) < 1: - raise logical_exception ("usage: .%s " % command) - chanlog (" ".join (args)) + elif command == 'convert': + if len(args) != 3 or args[1] != 'as': + raise logical_exception ("usage: .%s as " % command) + + value = float (args[0]) + valuetype = args[2] + + if valuetype in ['radians', 'degrees']: + if valuetype == 'radians': + radvalue = value + degvalue = (value * 180.) / math.pi + else: + radvalue = (value * math.pi) / 180. + degvalue = value + + self.privmsg (replyto, '%s radians, %s degrees (%s)' %(radvalue, degvalue, degvalue % 360.)) + elif valuetype in ['celsius', 'fahrenheit']: + if valuetype == 'celsius': + celvalue = value + fahrvalue = value * 1.8 + 32 + else: + celvalue = (value - 32) / 1.8 + fahrvalue = value + + self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue)) + else: + raise logical_exception ('unknown valuetype, expected one of: degrees, radians') # else: # raise logical_exception ("unknown command `.%s`" % command)