from obs import ObsClient
from base.BaseCore import BaseCore
baseCore = BaseCore()
cnx_=baseCore.cnx_
cursor_=baseCore.cursor_
# 创建ObsClient对象
obs_client = ObsClient(access_key_id='VEHN7D0TJ9316H8AHCAV', secret_access_key='heR353lvSWVPNU8pe2QxDtd8GDsO5L6PGH5eUoQY', server='https://obs.cn-north-1.myhuaweicloud.com')
def delete(object_keys):
    # 指定要删除的文件名列表
    bucket_name = 'zzsn'
    # object_keys = ['QYNotice/8921b4b0-7853-11ee-bcc0-000c29312880.pdf']

    # 批量删除文件
    for object_key in object_keys:
        resp = obs_client.deleteObject(bucket_name, object_key)
        if resp.status >= 200 and resp.status < 300:
            print(f"文件 {object_key} 删除成功！")
        else:
            print(f"文件 {object_key} 删除失败！ 错误码：{resp.errorCode}，错误信息：{resp.errorMessage}")

    # 关闭ObsClient对象
    obs_client.close()

if __name__=='__main__':
    query = "SELECT object_key FROM clb_sys_attachment WHERE type_id=8 AND source = '证监会' AND create_time >= '2023-10-30 16:46:09' AND create_time <= '2023-11-01 09:11:12'"
    cursor_.execute(query)
    results = cursor_.fetchall()
    object_keys = [item[0] for item in results]
    delete(object_keys)