<s> from urllib import urlopen <EOL> import json <EOL> URBANDICT_API_PREFIX = '<STR_LIT>' <EOL> class UrbanDictPlugin ( object ) : <EOL> def get_ud ( self , cardinal , user , channel , msg ) : <EOL> try : <EOL> word = msg . split ( '<STR_LIT:U+0020>' , <NUM_LIT:1> ) [ <NUM_LIT:1> ] <EOL> except IndexError : <EOL> cardinal . sendMsg ( channel , '<STR_LIT>' ) <EOL> return <EOL> try : <EOL> url = URBANDICT_API_PREFIX + word <EOL> f = urlopen ( url ) . read ( ) <EOL> data = json . loads ( f ) <EOL> word_def = data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> link = data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> response = '<STR_LIT>' % ( word , word_def , link ) <EOL> cardinal . sendMsg ( channel , response . encode ( '<STR_LIT:utf-8>' ) ) <EOL> except Exception : <EOL> cardinal . sendMsg ( channel , "<STR_LIT>" % word ) <EOL> get_ud . commands = [ '<STR_LIT>' ] <EOL> get_ud . help = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def setup ( ) : <EOL> return UrbanDictPlugin ( ) </s>
