47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
import redis
|
||
import utils
|
||
import mysql.connector
|
||
from config import *
|
||
|
||
def insert_measure_vector(conn,cursor):
|
||
|
||
redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, password=REDIS_PASSWORD, db=6)
|
||
# redis_client = redis.Redis(host=REDIS_HOST, port=REDIS_PORT, db=6)
|
||
# 执行SQL语句,更新数据
|
||
select_query = '''
|
||
SELECT ori_measure_id,ori_measure_name,measure_name FROM measure_config_half_year where year='2025'
|
||
'''
|
||
# select_query = '''
|
||
# SELECT ori_measure_id,ori_measure_name,measure_name FROM measure_config where year='2024'
|
||
# '''
|
||
cursor.execute(select_query)
|
||
records = cursor.fetchall()
|
||
print(records[:8])
|
||
#return
|
||
index = 1
|
||
for record in records:
|
||
if redis_client.hexists('measure_config_new', record[0]):
|
||
measure_vector = redis_client.hget('measure_config_new', record[0])
|
||
else:
|
||
print('新增指标',record[1])
|
||
vector = utils.embed_with_str_local(record[1])
|
||
measure_vector = str(vector)
|
||
#print(f'新增指标{index} 对应归一化指标为{record[2]}',record[1])
|
||
#index += 1
|
||
#vector = utils.embed_with_str_local(record[1])
|
||
#measure_vector = str(vector)
|
||
redis_client.hset('measure_config_new', record[0], measure_vector)
|
||
redis_client.close()
|
||
conn.close()
|
||
|
||
if __name__ == "__main__":
|
||
conn = mysql.connector.connect(
|
||
host=MYSQL_HOST,
|
||
user=MYSQL_USER,
|
||
password=MYSQL_PASSWORD,
|
||
database="financial_report_prod"
|
||
)
|
||
cursor = conn.cursor()
|
||
|
||
insert_measure_vector(conn,cursor)
|