<s> from flask import request , session , render_template , redirect , url_for <EOL> import glass <EOL> import foursquare <EOL> import config <EOL> app = glass . Application ( <EOL> client_id = config . GOOGLE_CLIENT_ID , <EOL> client_secret = config . GOOGLE_CLIENT_SECRET , <EOL> scopes = config . GOOGLE_SCOPES , <EOL> template_folder = "<STR_LIT>" , <EOL> static_url_path = '<STR_LIT>' , <EOL> static_folder = '<STR_LIT>' ) <EOL> app . web . secret_key = '<STR_LIT>' <EOL> FOURSQUARE_TOKENS = { } <EOL> def foursquare_client ( ) : <EOL> return foursquare . Foursquare ( client_id = config . FOURSQUARE_CLIENT_ID , client_secret = config . FOURSQUARE_CLIENT_SECRET , redirect_uri = config . FOURSQUARE_CLIENT_REDIRECT ) <EOL> @ app . web . route ( "<STR_LIT:/>" ) <EOL> def index ( ) : <EOL> return render_template ( "<STR_LIT>" , auth = False ) <EOL> @ app . subscriptions . login <EOL> def login ( user ) : <EOL> print "<STR_LIT>" % ( user . token ) <EOL> session [ '<STR_LIT>' ] = user . token <EOL> return redirect ( "<STR_LIT>" ) <EOL> @ app . subscriptions . location <EOL> def change_location ( user ) : <EOL> location = user . location ( ) <EOL> llat = location . get ( '<STR_LIT>' ) <EOL> llong = location . get ( '<STR_LIT>' ) <EOL> client = foursquare . Foursquare ( access_token = FOURSQUARE_TOKENS [ user . token ] ) <EOL> venues = client . venues . search ( params = { '<STR_LIT>' : llat + '<STR_LIT:U+002C>' + llong , '<STR_LIT>' : location . get ( '<STR_LIT>' ) } ) <EOL> if len ( venues [ '<STR_LIT>' ] ) > <NUM_LIT:0> : <EOL> user . timeline . post_template ( "<STR_LIT>" , venue = venues [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , llat = llat , llong = llong ) <EOL> @ app . web . route ( "<STR_LIT>" ) <EOL> def foursquare_authorize ( ) : <EOL> client = foursquare_client ( ) <EOL> return redirect ( client . oauth . auth_url ( ) ) <EOL> @ app . web . route ( "<STR_LIT>" ) <EOL> def foursquare_callback ( ) : <EOL> code = request . args . get ( '<STR_LIT:code>' , None ) <EOL> client = foursquare_client ( ) <EOL> if code is None or not '<STR_LIT>' in session : <EOL> return render_template ( "<STR_LIT>" , auth = False ) <EOL> access_token = client . oauth . get_token ( code ) <EOL> FOURSQUARE_TOKENS [ session [ '<STR_LIT>' ] ] = access_token <EOL> client . set_access_token ( access_token ) <EOL> user = client . users ( ) <EOL> username = user [ '<STR_LIT:user>' ] [ '<STR_LIT>' ] <EOL> print "<STR_LIT>" % ( access_token ) , username <EOL> userglass = glass . User ( app = app , token = session [ '<STR_LIT>' ] ) <EOL> userglass . timeline . post ( text = "<STR_LIT>" % username ) <EOL> return render_template ( "<STR_LIT>" , auth = True ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print "<STR_LIT>" % ( config . HOST , config . PORT ) <EOL> app . run ( port = config . PORT , host = config . HOST ) </s>
