"""
根据排名 找到信用代码
"""
import os
import re

import BaseCore
baseCore = BaseCore.BaseCore()
log = baseCore.getLogger()
cnx = baseCore.cnx
cursor = baseCore.cursor
file_path = 'D:\\BaiduNetdiskDownload'

file_list = os.listdir(file_path)
# print(pdf_list)
num = 1
for file in file_list:
    log.info(f'-----------当前文件{file}---------------')
    if '.zip' not in file:
        pass
    else:
        continue
    pdf_list = os.listdir(file_path + '\\' + file)
    log.info(f'当前文件夹有{len(pdf_list)}个文件')
    for pdf in pdf_list:
        # print(pdf)
        #获取rank
        try:
            id = pdf.split('-')[0]
            ename = pdf.split('-')[2]
            ename = re.split(r'\.pdf', ename, flags=re.IGNORECASE)[0]

            selectsql = f"select * from rankandcode where id = {id} and ename='{ename}'"
            cursor.execute(selectsql)
            result = cursor.fetchone()
            if result:
                pass
                # print(f'信用代码为：{result[1]}')
            else:
                print(f'错误匹配：{id}----{ename}')
        except:
            log.info(f'文件夹--{file} pdf---{pdf}')

