581 |
581 |
582 self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue)) |
582 self.privmsg (replyto, '%s degrees celsius, %s degrees fahrenheit' %(celvalue, fahrvalue)) |
583 else: |
583 else: |
584 raise logical_exception ('unknown valuetype, expected one of: degrees, radians (angle conversion), ' + |
584 raise logical_exception ('unknown valuetype, expected one of: degrees, radians (angle conversion), ' + |
585 'celsius, fahrenheit (temperature conversion)') |
585 'celsius, fahrenheit (temperature conversion)') |
|
586 elif command == 'urban' or command == 'ud': |
|
587 try: |
|
588 if len(args) < 1: |
|
589 raise logical_exception ('usage: %s <word>' % command) |
|
590 |
|
591 url = 'http://api.urbandictionary.com/v0/define?term=%s' % ('%20'.join (args)) |
|
592 response = urllib2.urlopen (url).read() |
|
593 data = json.loads (response) |
|
594 |
|
595 if 'list' in data and len(data['list']) > 0 and 'word' in data['list'][0] and 'definition' in data['list'][0]: |
|
596 word = data['list'][0]['word'] |
|
597 definition = data['list'][0]['definition'].replace ('\r', ' ').replace ('\n', ' ').replace (' ', ' ') |
|
598 up = data['list'][0]['thumbs_up'] |
|
599 down = data['list'][0]['thumbs_down'] |
|
600 self.privmsg (replyto, "\002%s\002: %s\0033 %d\003 up,\0035 %d\003 down" % (word, definition, up, down)) |
|
601 else: |
|
602 self.privmsg (replyto, "couldn't find a definition of \002%s\002" % args[0]) |
|
603 except logical_exception as e: |
|
604 raise e |
|
605 except Exception as e: |
|
606 raise logical_exception ('Urban dictionary lookup failed: %s' % `e`) |
586 # else: |
607 # else: |
587 # raise logical_exception ("unknown command `.%s`" % command) |
608 # raiee logical_exception ("unknown command `.%s`" % command) |
588 |
609 |
589 # |
610 # |
590 # Print a ticket announce to appropriate channels |
611 # Print a ticket announce to appropriate channels |
591 # |
612 # |
592 def announce_ticket (self, data): |
613 def announce_ticket (self, data): |