<s> """<STR_LIT>""" <EOL> import logging <EOL> from homeassistant . components . notify import DOMAIN , BaseNotificationService <EOL> from homeassistant . const import CONF_ACCESS_TOKEN <EOL> from homeassistant . helpers import validate_config <EOL> _LOGGER = logging . getLogger ( __name__ ) <EOL> REQUIREMENTS = [ '<STR_LIT>' ] <EOL> CONF_CONSUMER_KEY = "<STR_LIT>" <EOL> CONF_CONSUMER_SECRET = "<STR_LIT>" <EOL> CONF_ACCESS_TOKEN_SECRET = "<STR_LIT>" <EOL> def get_service ( hass , config ) : <EOL> """<STR_LIT>""" <EOL> if not validate_config ( { DOMAIN : config } , <EOL> { DOMAIN : [ CONF_CONSUMER_KEY , CONF_CONSUMER_SECRET , <EOL> CONF_ACCESS_TOKEN , <EOL> CONF_ACCESS_TOKEN_SECRET ] } , <EOL> _LOGGER ) : <EOL> return None <EOL> return TwitterNotificationService ( config [ CONF_CONSUMER_KEY ] , <EOL> config [ CONF_CONSUMER_SECRET ] , <EOL> config [ CONF_ACCESS_TOKEN ] , <EOL> config [ CONF_ACCESS_TOKEN_SECRET ] ) <EOL> class TwitterNotificationService ( BaseNotificationService ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , consumer_key , consumer_secret , access_token_key , <EOL> access_token_secret ) : <EOL> """<STR_LIT>""" <EOL> from TwitterAPI import TwitterAPI <EOL> self . api = TwitterAPI ( consumer_key , consumer_secret , access_token_key , <EOL> access_token_secret ) <EOL> def send_message ( self , message = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> resp = self . api . request ( '<STR_LIT>' , { '<STR_LIT:status>' : message } ) <EOL> if resp . status_code != <NUM_LIT:200> : <EOL> import json <EOL> obj = json . loads ( resp . text ) <EOL> error_message = obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:message>' ] <EOL> error_code = obj [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:code>' ] <EOL> _LOGGER . error ( "<STR_LIT>" , resp . status_code , <EOL> error_message , <EOL> error_code ) </s>
