def post_score(): """ Adds a score and returns the new score """ try: name = request.json['name'] score = request.json['score'] score = Score(name=name, score=score) key = score.put() score = Score.get(key) return json.dumps(dict(score=score.score, name=score.name)) except Exception as e: logging.exception(e)
def post_to_scores(): """ Adds a score and returns the top ten """ try: name = request.json['name'] score = request.json['score'] if isinstance(score, int): score = float(score) score_ = Score(name=name, score=score) key = score_.put() query = Score.all().order("-score") return json.dumps(dict(scores=[dict(name=result.name, score=result.score) for result in query.run(limit=10)])) except Exception as e: logging.exception(e)