Example #1
0
    def run(self, last_result: Any = None) -> Any:
        """
        执行入库
        :param last_result: 上个作业的结果
        :return: None
        """
        # 若备用文件存在,直接使用备用文件的数据进行存储
        backup_file = self._get_backup_file()
        if os.path.exists(backup_file):
            with open(backup_file) as f:
                data = safe_json_loads(f.read())

            self._sync_to_storage(data)
            os.remove(backup_file)
            return

        # 否则使用 SDK 请求得到的数据进行存储
        client = CloudSDKClient()
        req = CloudSDKRequest(self.idc, self.action, self.req_params)
        data = client.execute(req)

        try:
            self._sync_to_storage(data)
        except Exception as e:
            with open(backup_file, 'w') as f:
                f.write(safe_json_dumps(data))
                raise e
Example #2
0
    async def chat_message(self, event):
        """
        处理从组接收的信息
        """
        await self.send(text_data=safe_json_dumps({
            'status': event['status'],
            'step': event['step'],
            'progress': event['progress']
        }))

        if event['progress'] == 1:
            await self.close()
Example #3
0
    def _get_req(self) -> AbstractModel:
        """
        生成请求对象
        :return: 请求对象
        """
        # 获取接口信息
        name = self._interface['name']
        md = self._interface['module']
        version = self._interface['version']

        # 动态获取请求类
        req_class_path = f'tencentcloud.{md}.{version}.models'
        req_class_name = f'{name}Request'
        req_class = dynamic_import_class(f'{req_class_path}.{req_class_name}')

        # 实例化请求对象,并导入请求参数
        assert req_class, 'request class has not been import, check cloud_interface object'
        req = req_class()
        param_json = safe_json_dumps(self._params)
        req.from_json_string(param_json)
        return req
Example #4
0
def chk_settings() -> Path:
    p: Path = Path(SETTINGS_PATH)
    if not p.exists():
        print(strs.SET_NEXIST)
    else:
        SETTINGS = utils.safe_json_loads(p)
        if SETTINGS != None:
            try:
                p = Path(SETTINGS[K_DIR])
            except KeyError as err:
                print(strs.E_KEY.format(err, p))
                print(strs.E_SET_LOAD)
            else:
                return p

    if not utils.yes_no(strs.SET_GEN):
        if utils.safe_json_dumps(p, INIT_SETTINGS):
            print(strs.E_SET_INIT)
            return None
    else:
        print(strs.SET_EDIT)
        return None
    return Path(DEFAULT_PATH)
Example #5
0
 def to_internal_value(self, data):
     """
     数据是列表,存入前先编码化为 json
     """
     value = super().to_internal_value(data)
     return safe_json_dumps(value)