• 1


    import os

    from flask import Blueprint, jsonify, send_file
    from setting import MDB, COVER_PATH, MUSIC_PATH, QRCODE_PATH

    content_bp = Blueprint("content_bp", name)

    @content_bp.route("/content_list", methods=["POST"])
    def content_list():
    content = list(MDB.Content.find({}))

    for index, item in enumerate(content):
        content[index]["_id"] = str(item.get("_id"))
    
    return jsonify(content)
    

    @content_bp.route("/get_cover/", methods=["GET"])
    def get_cover(filename):

    cover_path = os.path.join(COVER_PATH, filename) # COVER_PATH = 'Cover' filename = 'xx.jpg'
    
    return send_file(cover_path)
    

    @content_bp.route("/get_music/", methods=["GET"])
    def get_music(filename):

    music_path = os.path.join(MUSIC_PATH, filename)
    
    return send_file(music_path)
    

    @content_bp.route("/toy_list", methods=["GET", 'POST'])
    def toy_list():
    toy = list(MDB.Devices.find({}))
    for index, item in enumerate(toy):
    toy[index]['_id'] = str(item.get('_id'))

    return jsonify(toy)
    

    from flask import Blueprint,request,jsonify
    from setting import MDB,RET

    devices_bp = Blueprint('devices_bp', name)

    @devices_bp.route('/scan_qr',methods=['post'])
    def scan_qr():
    device = request.form.to_dict() # device key
    print(device)
    device_info = MDB.Devices.find_one(device)
    if device_info:
    RET['CODE'] = 0
    RET['MSG'] = "扫描成功"
    RET['DATE'] = device
    # 描二维码成功
    else:
    # 扫描二维码失败 可能不是玩具二维码 数据库中未存在deviceKey
    RET['CODE'] = 1
    RET['MSG'] = "请扫描玩具二维码"
    RET['DATE'] = {}

    return jsonify(RET)
    

    @devices_bp.route('/bind_toy',methods=['post'])
    def bind_toy():
    '''

    :return:
    '''
    
    toy_info = request.form.to_dict()
    
    toy_info['avatar'] = 'Toy.jpg'
    toy_info['bind_user'] = toy_info.pop('user_id') # 删除并给一个新的值
    toy_info['friend_list'] = []
    
    MDB.Toys.insert_one(toy_info)
    
    toy_id = MDB.Toys.insert_one(toy_info)
    # MDB.Users.update_one({'_id':ObjectId(toy_info["bind_user"])})
    
    RET['CODE'] = 0
    RET['MSG'] = "绑定成功"
    RET['DATE'] = {}
    
    return jsonify(RET)
  • 相关阅读:
    【Networking】(转)一个非常好的epoll+线程池服务器Demo
    【算法】Logistic regression (逻辑回归) 概述
    【Linux】/dev/null 2>&1 详解
    单点登录与联合登录
    web项目报outmemory错误解决方案
    hadoop学习之HDFS
    ELK日志分析系统
    基于cookie共享的SSO中的遇到的问题
    oracle的隐式游标
    mysql截取字符串与reverse函数
  • 原文地址:https://www.cnblogs.com/Doner/p/11225237.html
Copyright © 2020-2023  润新知