cobalt.py

changeset 23
c25944cac3e6
parent 21
8c389f46a056
child 24
3ef436e7d7c1
equal deleted inserted replaced
22:3e2ce6056fb7 23:c25944cac3e6
37 import urllib 37 import urllib
38 import urllib2 38 import urllib2
39 import hgapi 39 import hgapi
40 import os 40 import os
41 import suds 41 import suds
42 import math
42 43
43 try: 44 try:
44 uid = os.geteuid() 45 uid = os.geteuid()
45 except: 46 except:
46 uid = -1 47 uid = -1
530 531
531 save_config() 532 save_config()
532 elif command == 'die': 533 elif command == 'die':
533 check_admin (sender, ident, host, command) 534 check_admin (sender, ident, host, command)
534 quit() 535 quit()
535 elif command == 'testlog': 536 elif command == 'convert':
536 check_admin (sender, ident, host, command) 537 if len(args) != 3 or args[1] != 'as':
537 if len(args) < 1: 538 raise logical_exception ("usage: .%s <value> as <valuetype>" % command)
538 raise logical_exception ("usage: .%s <message...>" % command) 539
539 chanlog (" ".join (args)) 540 value = float (args[0])
541 valuetype = args[2]
542
543 if valuetype in ['radians', 'degrees']:
544 if valuetype == 'radians':
545 radvalue = value
546 degvalue = (value * 180.) / math.pi
547 else:
548 radvalue = (value * math.pi) / 180.
549 degvalue = value
550
551 self.privmsg (replyto, '%s radians, %s degrees (%s)' %(radvalue, degvalue, degvalue % 360.))
552 elif valuetype in ['celsius', 'fahrenheit']:
553 if valuetype == 'celsius':
554 celvalue = value
555 fahrvalue = value * 1.8 + 32
556 else:
557 celvalue = (value - 32) / 1.8
558 fahrvalue = value
559
560 self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue))
561 else:
562 raise logical_exception ('unknown valuetype, expected one of: degrees, radians')
540 # else: 563 # else:
541 # raise logical_exception ("unknown command `.%s`" % command) 564 # raise logical_exception ("unknown command `.%s`" % command)
542 565
543 # 566 #
544 # Print a ticket announce to appropriate channels 567 # Print a ticket announce to appropriate channels

mercurial