<s> import pytumblr <EOL> import yaml <EOL> import os <EOL> import urlparse <EOL> import code <EOL> import oauth2 as oauth <EOL> def new_oauth ( yaml_path ) : <EOL> '''<STR_LIT>''' <EOL> print '<STR_LIT>' <EOL> consumer_key = raw_input ( '<STR_LIT>' ) <EOL> consumer_secret = raw_input ( '<STR_LIT>' ) <EOL> request_token_url = '<STR_LIT>' <EOL> authorize_url = '<STR_LIT>' <EOL> access_token_url = '<STR_LIT>' <EOL> consumer = oauth . Consumer ( consumer_key , consumer_secret ) <EOL> client = oauth . Client ( consumer ) <EOL> resp , content = client . request ( request_token_url , "<STR_LIT:POST>" ) <EOL> request_token = urlparse . parse_qs ( content ) <EOL> print '<STR_LIT>' % ( authorize_url , request_token [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> redirect_response = raw_input ( '<STR_LIT>' ) <EOL> url = urlparse . urlparse ( redirect_response ) <EOL> query_dict = urlparse . parse_qs ( url . query ) <EOL> oauth_verifier = query_dict [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> token = oauth . Token ( request_token [ '<STR_LIT>' ] , request_token [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> token . set_verifier ( oauth_verifier ) <EOL> client = oauth . Client ( consumer , token ) <EOL> resp , content = client . request ( access_token_url , "<STR_LIT:POST>" ) <EOL> access_token = urlparse . parse_qs ( content ) <EOL> tokens = { <EOL> '<STR_LIT>' : consumer_key , <EOL> '<STR_LIT>' : consumer_secret , <EOL> '<STR_LIT>' : access_token [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' : access_token [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> } <EOL> yaml_file = open ( yaml_path , '<STR_LIT>' ) <EOL> yaml . dump ( tokens , yaml_file , indent = <NUM_LIT:2> ) <EOL> yaml_file . close ( ) <EOL> return tokens <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> yaml_path = os . path . expanduser ( '<STR_LIT>' ) + '<STR_LIT>' <EOL> if not os . path . exists ( yaml_path ) : <EOL> tokens = new_oauth ( yaml_path ) <EOL> else : <EOL> yaml_file = open ( yaml_path , "<STR_LIT:r>" ) <EOL> tokens = yaml . safe_load ( yaml_file ) <EOL> yaml_file . close ( ) <EOL> client = pytumblr . TumblrRestClient ( <EOL> tokens [ '<STR_LIT>' ] , <EOL> tokens [ '<STR_LIT>' ] , <EOL> tokens [ '<STR_LIT>' ] , <EOL> tokens [ '<STR_LIT>' ] <EOL> ) <EOL> print '<STR_LIT>' <EOL> code . interact ( local = dict ( globals ( ) , ** { '<STR_LIT>' : client } ) ) </s>
