def getGears(self): """ Ajax query /getGears to extract gears from the database """ # Keep session alive cherrypy.session[self.DUMMY] = 'MyStravaGetGears' athlete_id = cherrypy.session.get(self.ATHLETE_ID) if athlete_id is None or not self.isAuthorized(athlete_id): gears = "" else: view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) gears = view.get_gears() view.close() return gears
def updategears(self): """ Ajax query /updatelocaldb to update the database """ view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) stravaRequest = StravaRequest(self.config, self._getOrRefreshToken()) view.update_gears(stravaRequest) gears = view.get_gears() view.close() return gears
def rebuildactivities(self): """ Ajax query /upgradelocaldb to upgrade the database """ view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) stravaRequest = StravaRequest(self.config, self._getOrRefreshToken()) view.rebuild_activities(stravaRequest) view.close()
def deleteactivity(self, activity_id): """ Ajax query /deleteactivity to delete a single activity using its id """ cherrypy.session[self.DUMMY] = 'MyStravaDeleteActivity' view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) view.delete_activity(activity_id) view.close() cherrypy.response.headers["Content-Type"] = "text/html" return "Activity deleted"
def updateactivities(self): """ Ajax query /updateactivities to update the activities database """ cherrypy.session[self.DUMMY] = 'MyStravaUpdateActivities' view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) stravaRequest = StravaRequest(self.config, self._getOrRefreshToken()) list_ids = view.update_activities(stravaRequest) activities = view.get_activities(list_ids=list_ids) view.close() return activities
def updateactivity(self, activity_id): """ Ajax query /updateactivity to update a single activity from its id """ cherrypy.session[self.DUMMY] = 'MyStravaUpdateActivity' view = StravaView(self.config, cherrypy.session.get(self.ATHLETE_ID)) stravaRequest = StravaRequest(self.config, self._getOrRefreshToken()) if isinstance(activity_id, str): activity_id = int(activity_id) try: activity = stravaRequest.client.get_activity(activity_id) view.update_activity(activity, stravaRequest) activity = view.get_activities(list_ids=activity_id) except requests.exceptions.HTTPError: # Page not found. Probably a deleted activity. activity = [] view.close() return activity
# from backend import readconfig from backend.stravadb import StravaView from backend import config view = StravaView(config, 4024698)