Ejemplo n.º 1
0
def trns_view():

    search_params = {}
    if len(request.args) > 0:
        qriteria = {}
        if request.args.has_key("start"):
            qriteria["$gte"] = request.args["start"]
        if request.args.has_key("end"):
            qriteria["$lt"] = request.args["end"]
        search_params["datetime"] = qriteria

    table_view = {"headers": [], "rows": []}
    field_filter = {"user_id": 0, "added": 0, "currency": 0}
    docs = g.db["transactions"].find(search_params, field_filter)
    first = True
    headers = ["_id", "datetime"]
    for doc in docs:
        vals = [str(doc.pop("_id")), doc.pop("datetime").strftime("%Y-%m-%d")]
        if first == True:
            headers = doc.keys()
            table_view["headers"] = headers
            first = False

        table_view["rows"].append(doc.values())

    return mjson.mongo_dumps(table_view)
Ejemplo n.º 2
0
Archivo: app.py Proyecto: timoh/GoCast
def trns_view():

    search_params = {}
    if len(request.args) > 0:
        qriteria = {}
        if request.args.has_key("start"):
            qriteria["$gte"] = request.args["start"]
        if request.args.has_key("end"):
            qriteria["$lt"] =  request.args["end"]
        search_params["datetime"] = qriteria

    table_view = {
        "headers" : [],
        "rows" : []
        }
    field_filter = { 
        "user_id": 0 , 
        "added": 0, 
        "currency": 0}
    docs = g.db["transactions"].find(search_params, field_filter)
    first = True
    headers = ["_id", "datetime"]
    for doc in docs:
        vals = [str(doc.pop("_id")), doc.pop("datetime").strftime("%Y-%m-%d")]
        if first == True:
            headers = doc.keys()
            table_view["headers"] = headers
            first = False

        table_view["rows"].append(doc.values())

    return mjson.mongo_dumps(table_view)
Ejemplo n.º 3
0
Archivo: app.py Proyecto: timoh/GoCast
def index(tid=None):
    if request.method == "GET":
        contraints = {}
        data = []
        if tid is not None:
            contraints = {"_id": ObjectId(tid)}
        rows = g.db.transactions.find(contraints)
        for row in rows:
            data.append(row)
        return mjson.mongo_dumps(data)

    elif request.method == "POST":
        form = request.form
        tid = g.db.transactions.insert({
            "user_id":
            form["user_id"],
            "amount":
            form["amount"],
            "datetime":
            form["datetime"] or datetime.utcnow()
        })

        if tid is None:
            return error("Cant saved this data into DB: {0}".format(
                str(request.form)))
        data = g.db.transactions.find_one({"_id": tid})
        return mjson.mongo_dumps(data)

    elif request.method == "PUT":
        tid = g.db.update({"_id": request.form["_id"]}, request.form, true)
        if tid is None:
            error("Update was unsuccessful")
        data = g.db.find_one({"_id": tid})
        return msjson.mongo_dumps(data)

    elif request.method == "DELETE":
        return error("Not implemented yet")
        doc = db.transactions.find({"_id": tid})
        if doc is None:
            return error("Deletion of `{0}` failed.")

    else:
        return error("You are too mysterious.[Wrong HTTP method.]")
Ejemplo n.º 4
0
Archivo: app.py Proyecto: timoh/GoCast
def users_stat(uid = 0):
    user = g.db["users_stat"].find_one({"$or": 
            [{"user_id": uid}, {"user_id": int(uid)}]})
    if uid == 1:
        uid = 4
    #user.update(
    print user["starts"], user["ends"]
    get_predictions(uid, user["starts"], user["ends"])
    if user is None:
        return error("User with given id `{0}` dont exist in database.".format(uid))
    else:
        return mjson.mongo_dumps(user)
Ejemplo n.º 5
0
Archivo: app.py Proyecto: timoh/GoCast
def index(tid = None):
    if request.method == "GET":
        contraints = {}
        data = []
        if tid is not None:
                contraints = {"_id": ObjectId(tid)}
        rows = g.db.transactions.find(contraints)
        for row in rows:
            data.append(row)
        return mjson.mongo_dumps(data)

    elif request.method == "POST":
        form = request.form
        tid = g.db.transactions.insert({
            "user_id" : form["user_id"],
            "amount": form["amount"],
            "datetime":  form["datetime"] or datetime.utcnow()})

        if tid is None:
            return error("Cant saved this data into DB: {0}".format(
                str(request.form)))
        data = g.db.transactions.find_one({"_id": tid})
        return mjson.mongo_dumps(data)
    
    elif request.method == "PUT":
        tid = g.db.update({"_id": request.form["_id"]}, 
            request.form, true)
        if tid is None:
            error("Update was unsuccessful")
        data = g.db.find_one({"_id": tid})
        return msjson.mongo_dumps(data)

    elif request.method == "DELETE":
        return error("Not implemented yet")
        doc = db.transactions.find({"_id": tid})
        if doc is None:
            return error("Deletion of `{0}` failed.")

    else:
        return error("You are too mysterious.[Wrong HTTP method.]")
Ejemplo n.º 6
0
Archivo: app.py Proyecto: timoh/GoCast
def users_stat(uid=0):
    user = g.db["users_stat"].find_one(
        {"$or": [{
            "user_id": uid
        }, {
            "user_id": int(uid)
        }]})
    if uid == 1:
        uid = 4
    #user.update(
    print user["starts"], user["ends"]
    get_predictions(uid, user["starts"], user["ends"])
    if user is None:
        return error(
            "User with given id `{0}` dont exist in database.".format(uid))
    else:
        return mjson.mongo_dumps(user)