<s> '''<STR_LIT>''' <EOL> from hogar . Utils . StringUtils import ignore_case_replace <EOL> import requests <EOL> import json <EOL> import logging <EOL> logger = logging . getLogger ( __name__ ) <EOL> api = '<STR_LIT>' <EOL> def enabled ( ) : <EOL> '''<STR_LIT>''' <EOL> return True <EOL> def applicable_types ( ) : <EOL> '''<STR_LIT>''' <EOL> return [ '<STR_LIT:text>' ] <EOL> def commands ( ) : <EOL> '''<STR_LIT>''' <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def should_reply ( ) : <EOL> '''<STR_LIT>''' <EOL> return True <EOL> def reply_type ( ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT:text>' <EOL> def run ( message ) : <EOL> '''<STR_LIT>''' <EOL> text = message [ '<STR_LIT:text>' ] <EOL> for command in commands ( ) : <EOL> text = ignore_case_replace ( command , '<STR_LIT>' , text ) . strip ( ) <EOL> try : <EOL> logger . debug ( '<STR_LIT>' . format ( <EOL> term = text ) ) <EOL> response = requests . get ( <EOL> api . format ( <EOL> term = text . encode ( '<STR_LIT:utf-8>' ) ) ) <EOL> except Exception , e : <EOL> logger . error ( '<STR_LIT>' . format ( <EOL> error = str ( e ) ) ) <EOL> return '<STR_LIT>' <EOL> if not response . status_code == requests . codes . ok : <EOL> return '<STR_LIT>' . format ( <EOL> term = text ) <EOL> try : <EOL> response_data = json . loads ( response . text . strip ( ) ) <EOL> except ValueError , e : <EOL> logger . error ( '<STR_LIT>' . format ( err = str ( e ) ) ) <EOL> return '<STR_LIT>' <EOL> try : <EOL> if response_data [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> except Exception , e : <EOL> logger . error ( '<STR_LIT>' . format ( <EOL> error = str ( e ) ) ) <EOL> return '<STR_LIT>' <EOL> try : <EOL> definition = response_data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> example = response_data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> author = response_data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> permalink = response_data [ '<STR_LIT:list>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> tags = '<STR_LIT:U+002CU+0020>' . join ( response_data [ '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> logger . error ( '<STR_LIT>' . format ( <EOL> error = str ( e ) ) ) <EOL> return '<STR_LIT>' <EOL> final_definition = u'<STR_LIT>' u'<STR_LIT>' . format ( <EOL> term = text , <EOL> author = author , <EOL> definition = definition , <EOL> example = example , <EOL> tags = tags , <EOL> permalink = permalink ) <EOL> return final_definition </s>
