当前位置: 首页>>代码示例>>Python>>正文


Python Tools.getData方法代码示例

本文整理汇总了Python中tools.Tools.getData方法的典型用法代码示例。如果您正苦于以下问题:Python Tools.getData方法的具体用法?Python Tools.getData怎么用?Python Tools.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tools.Tools的用法示例。


在下文中一共展示了Tools.getData方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: site_getDevices

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_getDevices():
    if not g.user:
        return jsonify({"error": "not loggued"}), 403
    r = get_db()
    obj = Tools.getData(r, "user_" + g.user)
    if len(obj) == 0:
        return jsonify({"error": "internal error, user object is empty"}), 500
    devices = {}
    if "devices" in obj:
        for k in obj["devices"]:
            devices[k] = Tools.getData(r, "device_" + k)
    return jsonify({"devices": devices})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:14,代码来源:main.py

示例2: site_removeDevices

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_removeDevices():
    if not g.user:
        return jsonify({"error": "not loggued"}), 403
    r = get_db()
    obj = Tools.getData(r, "user_" + g.user)
    if len(obj) == 0:
        return jsonify({"error": "internal error, user object is empty"}), 500
    if not "id" in request.form:
        return jsonify({"error": "id not present"}), 400
    _id = request.form['id']
    device = Tools.getData(r, "device_" + _id)
    if len(device) == 0:
        return jsonify({"error": "internal error, device object is empty"}), 500
    if "owner" in device:
        device.pop("owner", None)
        Tools.setData(r, "device_" + _id, device)
    if "devices" in obj:
        if obj["devices"].count(_id) > 0:
            obj["devices"].remove(_id)
            Tools.setData(r, "user_" + g.user, obj)
    return jsonify({"removed": "true", "id": _id})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:23,代码来源:main.py

示例3: site_addDevices

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_addDevices():
    if not g.user:
        return jsonify({"error": "not loggued"}), 403
    r = get_db()
    obj = Tools.getData(r, "user_" + g.user)
    if len(obj) == 0:
        return jsonify({"error": "internal error, user object is empty"}), 500
    if not "code" in request.form:
        return jsonify({"error": "code not present"}), 400
    _6digits = request.form['code']
    if not r.hexists("waiting_devices", _6digits):
        return jsonify({"error": "device not known"}), 404
    _id = r.hget("waiting_devices", _6digits)
    device = Tools.getData(r, "device_" + _id)
    if len(device) == 0:
        return jsonify({"error": "internal error, device object is empty"}), 500
    if not "devices" in obj:
        obj["devices"] = []
    obj["devices"].append(_id)
    device["owner"] = obj["email"]
    Tools.setData(r, "device_" + _id, device)
    Tools.setData(r, "user_" + g.user, obj)
    return jsonify({"added": "true", "id": _id})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:25,代码来源:main.py

示例4: site_subscribe

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_subscribe():
    if g.user:
        return jsonify({"error": "already loggued"}), 403
    if not "email" in request.form and len(request.form["email"]) > 0:
        return jsonify({"error": "email not present"}), 400
    email = request.form["email"]
    if not "password" in request.form and len(request.form["password"]) > 0:
        return jsonify({"error": "password not present"}), 400
    password = request.form["password"]
    r = get_db()
    if len(Tools.getData(r, "user_" + email)) > 0:
        return jsonify({"error": "user already exists"}), 400
    Tools.setData(r, "user_" + email, {"email": email, "password": hashlib.sha1(password).hexdigest()})
    return jsonify({"subscribed": "true"})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:16,代码来源:main.py

示例5: site_getCoordinates

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_getCoordinates():
    if not g.user:
        return jsonify({"error": "not loggued"}), 403
    r = get_db()
    obj = Tools.getData(r, "user_" + g.user)
    if len(obj) == 0:
        return jsonify({"error": "internal error, user object is empty"}), 500
    _id = request.args.get('id', None)
    if not "devices" in obj or _id not in obj["devices"]:
        return jsonify({"error": "you are not the owner of the device"}), 403
    _from = int(request.args.get("from", "100"))
    _count = int(request.args.get("count", "100"))
    if _count > 500:
        return jsonify({"error": "range too big"}), 400
    coordinates = r.lrange("coordinates_" + _id, -1 * _from, _count)
    return jsonify({"id": _id, "coordinates": coordinates})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:18,代码来源:main.py

示例6: site_login

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def site_login():
    if g.user:
        return jsonify({"error": "already loggued"}), 403
    if not "email" in request.form and len(request.form["email"]) > 0:
        return jsonify({"error": "email not present"}), 400
    email = request.form["email"]
    if not "password" in request.form and len(request.form["password"]) > 0:
        return jsonify({"error": "password not present"}), 400
    password = request.form["password"]
    r = get_db()
    obj = Tools.getData(r, "user_" + email)
    if len(obj) == 0:
        return jsonify({"error": "user doesn't exist"}), 404
    if obj["password"] != hashlib.sha1(password).hexdigest():
        return jsonify({"error": "incorrect password"}), 403
    session["user_id"] = email
    return jsonify({"loggued": "true"})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:19,代码来源:main.py

示例7: phone_post_coordinates

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def phone_post_coordinates():
    if not "id" in request.form:
        return jsonify({"error": "id not present"}), 400
    if not "signature" in request.form:
        return jsonify({"error": "signature not present"}), 400
    if not "long" in request.form or not "lat" in request.form:
        return jsonify({"error": "position not present"}), 400
    r = get_db()
    _signature = request.form['signature']
    _id = request.form['id']
    _long = float(request.form['long'])
    _lat = float(request.form['lat'])
    obj = Tools.getData(r, "device_" + _id)
    if not "secret" in obj:
        return jsonify({"error": "secret not present"}), 400
    if not Tools.checkSignature(_id, obj["secret"], _signature):
        return jsonify({"error": "wrong signature"}), 400
    r.lpush("coordinates_" + _id, str(_lat) + ", " + str(_long))
    return jsonify({"saved": "true"})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:21,代码来源:main.py

示例8: phone_registered

# 需要导入模块: from tools import Tools [as 别名]
# 或者: from tools.Tools import getData [as 别名]
def phone_registered():
    r = get_db()
    if not "code" in request.form:
        return jsonify({"error": "code not present"}), 400
    if not "signature" in request.form:
        return jsonify({"error": "signature not present"}), 400
    _6digits = request.form['code']
    _signature = request.form['signature']
    if not r.hexists("waiting_devices", _6digits):
        return jsonify({"error": "device not known"}), 404
    _id = r.hget("waiting_devices", _6digits)
    obj = Tools.getData(r, "device_" + _id)
    print("registered: device_" + _id + ", obj: " + str(obj) + ", 6digits" + _6digits + ", signature: " + _signature) 
    if not "secret" in obj:
        return jsonify({"error": "secret not present"}), 404
    if not Tools.checkSignature(_id, obj["secret"], _signature):
        return jsonify({"error": "wrong signature"}), 400
    if not "owner" in obj:
        return jsonify({"registered": "false"})
    return jsonify({"registered": "true", "owner": obj["owner"]})
开发者ID:steven-martins,项目名称:trakkar-py,代码行数:22,代码来源:main.py


注:本文中的tools.Tools.getData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。