<s> '''<STR_LIT>''' <EOL> __author__ = '<STR_LIT>' <EOL> import ConfigParser <EOL> import getopt <EOL> import os <EOL> import sys <EOL> import twitter <EOL> USAGE = '''<STR_LIT>''' <EOL> def PrintUsageAndExit ( ) : <EOL> print USAGE <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> def GetConsumerKeyEnv ( ) : <EOL> return os . environ . get ( "<STR_LIT>" , None ) <EOL> def GetConsumerSecretEnv ( ) : <EOL> return os . environ . get ( "<STR_LIT>" , None ) <EOL> def GetAccessKeyEnv ( ) : <EOL> return os . environ . get ( "<STR_LIT>" , None ) <EOL> def GetAccessSecretEnv ( ) : <EOL> return os . environ . get ( "<STR_LIT>" , None ) <EOL> class TweetRc ( object ) : <EOL> def __init__ ( self ) : <EOL> self . _config = None <EOL> def GetConsumerKey ( self ) : <EOL> return self . _GetOption ( '<STR_LIT>' ) <EOL> def GetConsumerSecret ( self ) : <EOL> return self . _GetOption ( '<STR_LIT>' ) <EOL> def GetAccessKey ( self ) : <EOL> return self . _GetOption ( '<STR_LIT>' ) <EOL> def GetAccessSecret ( self ) : <EOL> return self . _GetOption ( '<STR_LIT>' ) <EOL> def _GetOption ( self , option ) : <EOL> try : <EOL> return self . _GetConfig ( ) . get ( '<STR_LIT>' , option ) <EOL> except : <EOL> return None <EOL> def _GetConfig ( self ) : <EOL> if not self . _config : <EOL> self . _config = ConfigParser . ConfigParser ( ) <EOL> self . _config . read ( os . path . expanduser ( '<STR_LIT>' ) ) <EOL> return self . _config <EOL> def main ( ) : <EOL> try : <EOL> shortflags = '<STR_LIT:h>' <EOL> longflags = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> opts , args = getopt . gnu_getopt ( sys . argv [ <NUM_LIT:1> : ] , shortflags , longflags ) <EOL> except getopt . GetoptError : <EOL> PrintUsageAndExit ( ) <EOL> consumer_keyflag = None <EOL> consumer_secretflag = None <EOL> access_keyflag = None <EOL> access_secretflag = None <EOL> encoding = None <EOL> for o , a in opts : <EOL> if o in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> PrintUsageAndExit ( ) <EOL> if o in ( "<STR_LIT>" ) : <EOL> consumer_keyflag = a <EOL> if o in ( "<STR_LIT>" ) : <EOL> consumer_secretflag = a <EOL> if o in ( "<STR_LIT>" ) : <EOL> access_keyflag = a <EOL> if o in ( "<STR_LIT>" ) : <EOL> access_secretflag = a <EOL> if o in ( "<STR_LIT>" ) : <EOL> encoding = a <EOL> message = '<STR_LIT:U+0020>' . join ( args ) <EOL> if not message : <EOL> PrintUsageAndExit ( ) <EOL> rc = TweetRc ( ) <EOL> consumer_key = consumer_keyflag or GetConsumerKeyEnv ( ) or rc . GetConsumerKey ( ) <EOL> consumer_secret = consumer_secretflag or GetConsumerSecretEnv ( ) or rc . GetConsumerSecret ( ) <EOL> access_key = access_keyflag or GetAccessKeyEnv ( ) or rc . GetAccessKey ( ) <EOL> access_secret = access_secretflag or GetAccessSecretEnv ( ) or rc . GetAccessSecret ( ) <EOL> if not consumer_key or not consumer_secret or not access_key or not access_secret : <EOL> PrintUsageAndExit ( ) <EOL> api = twitter . Api ( consumer_key = consumer_key , consumer_secret = consumer_secret , <EOL> access_token_key = access_key , access_token_secret = access_secret , <EOL> input_encoding = encoding ) <EOL> try : <EOL> status = api . PostUpdate ( message ) <EOL> except UnicodeDecodeError : <EOL> print "<STR_LIT>" <EOL> print "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> print "<STR_LIT>" % ( status . user . name , status . text ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
