def POST(self): try: args = web.input(track_id="", token=None) logging.debug("Vote request: %s" % args) sender = auth.get_id_by_token(args.token) if sender is None: raise web.forbidden("Bad token.") if args.track_id.isdigit(): track_id = int(args.track_id) else: track_id = tracks.get_last_track_id() weight = tracks.add_vote(track_id, sender, self.vote_value) if weight is None: return {"status": "error", "message": "No such track."} database.commit() message = 'OK, current weight of track #%u is %.04f.' % (track_id, weight) return { "status": "ok", "message": message, "id": track_id, "weight": weight, } except web.Forbidden: raise except Exception, e: log.log_error(str(e), e) return {"status": "error", "message": str(e)}
def POST(self): try: args = web.input(track_id="", token=None) logging.debug("Vote request: %s" % args) sender = auth.get_id_by_token(args.token) if sender is None: raise web.forbidden("Bad token.") if args.track_id.isdigit(): track_id = int(args.track_id) else: track_id = tracks.get_last_track_id() weight = tracks.add_vote(track_id, sender, self.vote_value) if weight is None: return {"status": "error", "message": "No such track."} database.commit() message = 'OK, current weight of track #%u is %.04f.' % (track_id, weight) return { "status": "ok", "message": message, "id": track_id, "weight": weight, } except web.Forbidden: raise except Exception, e: log.log_exception(str(e), e) return {"status": "error", "message": str(e)}
def GET(self): track_id = tracks.get_last_track_id() if track_id is None: return None track = tracks.get_track_by_id(track_id) if track is None: return None track["current_ts"] = int(time.time()) return track
def GET(self): from listeners import get_count track_id = tracks.get_last_track_id() if track_id is None: return None track = tracks.get_track_by_id(track_id) if track is None: return None track["current_ts"] = int(time.time()) track["listeners"] = get_count() or 0 return track