Beispiel #1
0
    def insertArtical():

        '''
        :return: Consulting the common.py in app package for details
        '''
        '''
         method 1 get params from form
        '''
        articalId = request.form.get('articalId')
        title = request.form.get('title')
        content = request.form.get('content')
        tag = request.form.get('tag')
        createTime = request.form.get('createTime')
        updateTime = request.form.get('updateTime')
        createPeople = request.form.get('createPeople')

        '''
         method 2 get params from url
        '''
        # articalId = request.args.get('articalId')
        # title = request.args.get('title')
        # content = request.args.get('content')
        # tag = request.args.get('tag')
        # createTime = request.args.get('createTime')
        # updateTime = request.args.get('updateTime')
        # createPeople = request.args.get('createPeople')
        artical = handlearticaloptions(articalId=articalId, title=title, content=content, tag=tag,createTime=createTime,
                                    updateTime=updateTime,createPeople=createPeople )
        result = handlearticaloptions.insert(handlearticaloptions, artical)
        print(42,request.form,result,artical.id)
        if artical.id:
            return jsonify(Common.trueReturn(Common, 'i like yz'))
        else:
            return jsonify(Common.falseReturn(Common, 'i like yz'))
 def getUser(userId):
     user = Users.get(Users, userId)
     if user is None:
         return jsonify(Common.falseReturn(Common, None, '找不到数据'))
     else:
         return jsonify(Common.trueReturn(Common, Users.output(Users,
                                                               user)))
 def deleteUser(userId):
     user = Users.get(Users, userId)
     if user is None:
         return jsonify(Common.falseReturn(Common, None, '找不到要删除的数据'))
     else:
         deleteRow = Users.delete(Users, userId)
         user = Users.get(Users, userId)
         if user is None:
             return getUsers()
         else:
             return jsonify(Common.falseReturn(Common, None, '删除失败'))
Beispiel #4
0
 def deleteArtical(articalId):
     artical = handlearticaloptions.getArticalById(handlearticaloptions, articalId)
     if artical is None:
         return jsonify(Common.falseReturn(Common, None, '找不到要删除的数据'))
     else:
         result = handlearticaloptions.delete(handlearticaloptions, articalId)
         print(66,result)
         if result is None:
             return jsonify(Common.falseReturn(Common, None, '删除成功'))
         else:
             return jsonify(Common.trueReturn(Common, None, '删除失败'))
Beispiel #5
0
 def addComments():
     username = request.form.get('username')
     content = request.form.get('comments')
     if username is None:
         return jsonify(Common.falseReturn(Common, None, '尚未登录,无法评论'))
     elif content == "":
         # 评论不能为空
         return jsonify(Common.falseReturn(Common, None, '内容为空,评论失败'))
     else:
         comment = Comments(username=username, content=content)
         result = Comments.add(Comments, comment)
         return getComments()
    def get(self, request):

        # Get stored device config objects
        config_objects = DeviceConfigModel.objects.all()
        configs = []
        for config_object in config_objects:
            config = DeviceConfigViewer()
            config.parse(config_object)
            configs.append(config)

        # Sort configs by name
        configs.sort(key=lambda x: x.name)

        # Get current config
        current_config = Common.get_device_state_value("config_uuid")

        # Convert current config uuid to name
        if current_config != None:
            for config in configs:
                if config.uuid == current_config:
                    current_config = config.name
                    break

        # Build and return response
        response = {"configs": configs, "current_config": current_config}
        return Response(response)
 def api_upload():
     # 获取存储路径
     file_dir = os.path.join(basedir, app.config['UPLOAD_FOLDER'])
     if not os.path.exists(file_dir):
         os.makedirs(file_dir)
     # 获取图片和图片名称
     img = request.files['screenshot']
     filename = request.form.get("filename")
     print(img)
     if img:
         if img and allowed_file(filename):
             fname = filename
             ext = fname.rsplit('.', 1)[1]
             new_filename = Pic_str().create_uuid() + '.' + ext
             img.save(os.path.join(file_dir, new_filename))
             # 图片需要转成BASE64
             image = get_file_content('app/upload/'+new_filename)
         # BASE64转字符串
         image64 = str(image, 'utf-8')
         imageType = "BASE64"
         groupIdList = "GamesOfThrone"
         # 设置人脸识别参数
         options = {}
         options["max_face_num"] = 5
         options["match_threshold"] = 70
         options["max_user_num"] = 5
         # 图像识别返回内容
         return client.multiSearch(image64, imageType, groupIdList, options)
     else:
         return jsonify(Common.falseReturn(Common, None, "图片上传失败"))
Beispiel #8
0
 def updateArtical(articalId):
     artical = handlearticaloptions.getArticalById(handlearticaloptions, articalId)
     if artical is None:
         return jsonify(Common.falseReturn(Common, None, '找不到要修改的数据'))
     else:
         artical.title = request.form.get('title')
         artical.content = request.form.get('content')
         artical.tag = request.form.get('tag')
         artical.updateTime = request.form.get('updateTime')
         artical.createPeople = request.form.get('createPeople')
         result = handlearticaloptions.update(handlearticaloptions, artical)
         print(56,result)
         if artical.id:
             return getAtricalById(articalId)
         else:
             return jsonify(Common.falseReturn(Common, None, result))
 def addUser():
     user_name = request.form.get('user_name')
     user_password = request.form.get('user_password')
     user_nickname = request.form.get('user_nickname')
     user_email = request.form.get('user_email')
     user = Users(user_name=user_name,
                  user_password=user_password,
                  user_nickname=user_nickname,
                  user_email=user_email)
     result = Users.add(Users, user)
     if user.user_id:
         return getUser(user.user_id)
     else:
         return jsonify(Common.falseReturn(Common, None, result))
    def get_thread_parameters(self):

        # Initialize thread modes dict
        modes = {}
        healths = {}

        # Get device and recipe modes
        modes["Device Mode"] = Common.get_device_state_value("mode")
        modes["Recipe Mode"] = Common.get_recipe_state_value("mode")

        # Get peripherals mode and health if they exist
        peripheral_dict = Common.get_peripheral_dict()
        if peripheral_dict != None:
            for peripheral_name in peripheral_dict:
                individual_peripheral_dict = peripheral_dict[peripheral_name]
                modes[peripheral_name] = individual_peripheral_dict.get(
                    "mode", None)

                # TODO: re-instate this
                healths[peripheral_name] = individual_peripheral_dict.get(
                    "health", None)

        # Return thread modes
        return modes, healths
    def updateUser(userId):
        user = Users.get(Users, userId)
        if user is None:
            return jsonify(Common.falseReturn(Common, None, '找不到要修改的数据'))
        else:
            user_name = request.form.get('user_name')
            user_password = request.form.get('user_password')
            user_nickname = request.form.get('user_nickname')
            user_email = request.form.get('user_email')

            user.user_name = user_name
            user.user_password = user_password
            user.user_nickname = user_nickname
            user.user_email = user_email

            result = Users.update(Users)
            return getUser(user.user_id)
Beispiel #12
0
 def news():
     return jsonify(Common.trueReturn(Common, '这是新闻模块', "提示信息"))
    def get_environment_summary(self, peripheral_type):
        """ Gets environment summary of current reported --> desired value 
            for each variable in shared state. """
        self.logger.debug("Getting environment summary")

        # Initialize class for common functions
        common = Common()

        # Initialize summary dict
        summary = {}

        # Get environment dict
        environment_dict = Common.get_environment_dict()
        if environment_dict == None:
            return summary

        # Log all variables in reported values
        for variable in environment_dict[peripheral_type]["reported"]:
            # Get peripheral info
            if peripheral_type == "sensor":
                info = common.get_sensor_variable_info(variable)
            elif peripheral_type == "actuator":
                info = common.get_actuator_variable_info(variable)
            else:
                raise ValueError(
                    "`peripheral_type` must be either `sensor` or `actuator`")

            if info is None:
                continue

            # Get peripheral name and unit
            name = info["name"]["verbose"]
            unit = info["unit"]["brief"]

            # Get reported and desired values
            reported = str(
                environment_dict[peripheral_type]["reported"][variable])
            if variable in environment_dict[peripheral_type]["desired"]:
                desired = str(
                    environment_dict[peripheral_type]["desired"][variable])
            else:
                desired = "None"

            name_string = name + " (" + unit + ")"
            summary[name_string] = reported + " --> " + desired

        # Log remaining variables in desired
        for variable in environment_dict[peripheral_type]["desired"]:

            # Skip over repeated variables
            if variable in environment_dict[peripheral_type]["reported"]:
                continue

            # Get peripheral info
            if peripheral_type == "sensor":
                info = common.get_sensor_variable_info(variable)
            elif peripheral_type == "actuator":
                info = common.get_actuator_variable_info(variable)
            else:
                raise ValueError(
                    "`peripheral_type` must be either `sensor` or `actuator`")

            if info is None:
                continue

            # Get peripheral name and unit
            name = info["name"]["verbose"]
            unit = info["unit"]["brief"]

            # Get reported and desired values
            desired = str(
                environment_dict[peripheral_type]["desired"][variable])
            reported = "None"
            name_string = name + " (" + unit + ")"
            summary[name_string] = reported + " --> " + desired

        return summary
 def __init__(self):
     """ Initialize recipe viewer. """
     self.mode = Common.get_recipe_state_value("mode")
     self.recipe_name = Common.get_recipe_state_value("recipe_name")
     self.recipe_uuid = Common.get_recipe_state_value("recipe_uuid")
     self.start_datestring = Common.get_recipe_state_value(
         "start_datestring")
     self.percent_complete_string = Common.get_recipe_state_value(
         "percent_complete_string")
     self.time_elapsed_string = Common.get_recipe_state_value(
         "time_elapsed_string")
     self.time_elapsed_minutes = Common.get_recipe_state_value(
         "last_update_minute")
     self.time_remaining_string = Common.get_recipe_state_value(
         "time_remaining_string")
     self.time_remaining_minutes = Common.get_recipe_state_value(
         "time_remaining_minutes")
     self.current_phase = Common.get_recipe_state_value("current_phase")
     self.current_cycle = Common.get_recipe_state_value("current_cycle")
     self.current_environment_name = Common.get_recipe_state_value(
         "current_environment_name")
 def index():
     return jsonify(Common.trueReturn(Common, '用户模块'))
Beispiel #16
0
 def getComments():
     comments = Comments.getAll(Comments)
     output = []
     for comment in comments:
         output.append(Comments.output(Comments, comment))
     return jsonify(Common.trueReturn(Common, output))
 def __init__(self):
     self.iot_dict = Common.get_iot_dict()
Beispiel #18
0
 def getAtricalById(articalId):
     artical = handlearticaloptions.getArticalById(handlearticaloptions, articalId)
     if artical is None:
         return jsonify(Common.falseReturn(Common, None, '找不到数据'))
     else:
         return jsonify(Common.trueReturn(Common, handlearticaloptions.output(handlearticaloptions, artical)))
 def __init__(self):
     self.connect_dict = Common.get_connect_dict()
 def __init__(self):
     self.resource_dict = Common.get_resource_dict()
 def getUsers():
     users = Users.getAll(Users)
     output = []
     for user in users:
         output.append(Users.output(Users, user))
     return jsonify(Common.trueReturn(Common, output))
 def __init__(self):
     self.upgrade_dict = Common.get_upgrade_dict()
Beispiel #23
0
 def getAllAtricals():
     articals = handlearticaloptions.getAll(handlearticaloptions)
     output = []
     for artical in articals:
         output.append(handlearticaloptions.output(articals, artical))
     return jsonify(Common.trueReturn(Common, output))