import pandas as pd
# from pandas import DataFrame as df
import pymysql

cnx = pymysql.connect(host='114.116.44.11', user='caiji', password='f7s0&7qqtK', db='clb_project', charset='utf8mb4')
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
df_all = pd.read_excel('D:\\企业数据\\数据组提供\\2023专精特新企业名单_20240205 (2)(1).xlsx', dtype=str)
list_com = []
for num_df in range(len(df_all)):
    com_name = str(df_all['企业名称'][num_df])

    dic_com = {
        'social_code': '',
        'com_name': com_name
    }

    with cnx.cursor() as cursor:
        sel_sql = '''select social_credit_code from sys_base_enterprise where name = %s '''
        cursor.execute(sel_sql, com_name)
        selects = cursor.fetchone()
        if selects:
            print(f'【{num_df}/{len(df_all)}】==={com_name}找到')
            social_code = selects[0]
        else:
            print(f'【{num_df}/{len(df_all)}】==={com_name}未找到')
            social_code = ''

    df_all['信用代码列'][num_df] = str(social_code)
    df_all.to_excel('D:\\企业数据\\数据组提供\\名单整合2.xlsx', index=False)