def get(self): user = users.get_current_user() if user: auth_token = self.request.get("oauth_token") if auth_token: credentials = constants.get_client().get_credentials(auth_token) old_userinfos = UserInfo.all().filter('user ='******'token'], secret = credentials['secret'], is_ready=False, is_authorized=True, last_checkin=0, last_updated=datetime.now(), color_scheme='fire', level_max=int(constants.level_const), checkin_count=0, venue_count=0) fetch_foursquare_data.update_user_info(userinfo) fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10) taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key())#, queue_name='initial-checkin-fetching') self.redirect("/") else: self.redirect(constants.get_client().get_authorization_url()) else: self.redirect(users.create_login_url(self.request.uri))
def get(self): user = users.get_current_user() if user: oauth_token = self.request.get("oauth_token") def get_new_fs_and_credentials(): oauth_token, oauth_secret = constants.get_oauth_strings() credentials = foursquare.OAuthCredentials(oauth_token, oauth_secret) fs = foursquare.Foursquare(credentials) return fs, credentials if oauth_token: old_userinfos = UserInfo.all().filter('user ='******'token =', oauth_token).get() try: user_token = fs.access_token(oauth.OAuthToken(apptoken.token, apptoken.secret)) credentials.set_access_token(user_token) userinfo = UserInfo(user = user, token = credentials.access_token.key, secret = credentials.access_token.secret, is_ready=False, is_authorized=True, last_checkin=0, last_updated=datetime.now(), color_scheme='fire', level_max=int(constants.level_const), checkin_count=0, venue_count=0) except DownloadError, err: if str(err).find('ApplicationError: 5') >= 0: pass # if something bad happens on OAuth, then it currently just redirects to the signup page #TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code else: raise err try: fetch_foursquare_data.update_user_info(userinfo) fetch_foursquare_data.fetch_and_store_checkins(userinfo, limit=10) taskqueue.add(url='/fetch_foursquare_data/all_for_user/%s' % userinfo.key()) except foursquare.FoursquareRemoteException, err: if str(err).find('403 Forbidden') >= 0: pass # if a user tries to sign up while my app is blocked, then it currently just redirects to the signup page #TODO find a better way to handle this case, but it's not clear there is a simple way to do it without messing up a bunch of code else: raise err except DownloadError: pass #TODO make this better, but I'd rather throw the user back to the main page to try again than show the user an error.