Ejemplo n.º 1
0
    def post(self):
        # 1. Get data from json body
        json_score = request.get_json()
        name = json_score["name"]  # dictionary
        score = json_score["score"]
        added_time = datetime.now()

        # 2. Add name, score into database
        new_score = Score()
        new_score.name = name
        new_score.score = score
        new_score.added_time = added_time
        new_score.save()

        return {
            'success': 1,
            'data': {
                'name': new_score.name,
                'score': new_score.score
            }
        }
Ejemplo n.º 2
0
from mlab import mlab_connect
from models.score import Score
from datetime import datetime, timedelta
from random import randint

mlab_connect()

for i in range(10):
    score = Score()
    score.name = "past"
    score.score = 120
    score.added_time = datetime.now() - timedelta(days=randint(1, 5))
    score.save()