<s> from flask import Flask , url_for , session , jsonify <EOL> from flask . ext . oauthlib . contrib . client import OAuth <EOL> class AppConfig ( object ) : <EOL> DEBUG = True <EOL> SECRET_KEY = '<STR_LIT>' <EOL> DOUBAN_CLIENT_ID = '<STR_LIT>' <EOL> DOUBAN_CLIENT_SECRET = '<STR_LIT>' <EOL> DOUBAN_SCOPE = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> app = Flask ( __name__ ) <EOL> app . config . from_object ( AppConfig ) <EOL> app . config . from_pyfile ( '<STR_LIT>' , silent = True ) <EOL> oauth = OAuth ( app ) <EOL> douban = oauth . remote_app ( <EOL> name = '<STR_LIT>' , <EOL> version = '<STR_LIT:2>' , <EOL> endpoint_url = '<STR_LIT>' , <EOL> access_token_url = '<STR_LIT>' , <EOL> refresh_token_url = '<STR_LIT>' , <EOL> authorization_url = '<STR_LIT>' , <EOL> compliance_fixes = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def home ( ) : <EOL> if obtain_douban_token ( ) : <EOL> response = douban . get ( '<STR_LIT>' ) <EOL> return jsonify ( response = response . json ( ) ) <EOL> return '<STR_LIT>' % url_for ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def oauth_douban ( ) : <EOL> callback_uri = url_for ( '<STR_LIT>' , _external = True ) <EOL> return douban . authorize ( callback_uri ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def oauth_douban_callback ( ) : <EOL> response = douban . authorized_response ( ) <EOL> if response : <EOL> store_douban_token ( response ) <EOL> return repr ( dict ( response ) ) <EOL> else : <EOL> return '<STR_LIT>' % ( url_for ( '<STR_LIT>' ) ) <EOL> @ douban . tokengetter <EOL> def obtain_douban_token ( ) : <EOL> return session . get ( '<STR_LIT>' ) <EOL> @ douban . tokensaver <EOL> def store_douban_token ( token ) : <EOL> session [ '<STR_LIT>' ] = token <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> app . run ( ) </s>
