|
|
|
@ -1,6 +1,7 @@
|
|
|
|
#导入新高新低数据
|
|
|
|
#导入新高新低数据
|
|
|
|
import pymysql
|
|
|
|
import pymysql
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def toTransNewRecordData(db_conn_a,dbcursor_a,db_conn_b,dbcursor_b,trade_date):
|
|
|
|
# #数据库A的连接信息;NAS数据库
|
|
|
|
# #数据库A的连接信息;NAS数据库
|
|
|
|
# db_a_config = {
|
|
|
|
# db_a_config = {
|
|
|
|
# 'host': '192.168.0.222',
|
|
|
|
# 'host': '192.168.0.222',
|
|
|
|
@ -19,39 +20,48 @@ import pymysql
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
# 数据库A的连接信息;腾讯云数据库
|
|
|
|
# # 数据库A的连接信息;腾讯云数据库
|
|
|
|
db_a_config = {
|
|
|
|
# db_a_config = {
|
|
|
|
'host': '124.223.98.178',
|
|
|
|
# 'host': '124.223.98.178',
|
|
|
|
'user': 'root',
|
|
|
|
# 'user': 'root',
|
|
|
|
'password': '1qazse42W3',
|
|
|
|
# 'password': '1qazse42W3',
|
|
|
|
'db': 'ry',
|
|
|
|
# 'db': 'ry',
|
|
|
|
'charset': 'utf8mb4',
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
# 数据库B的连接信息;腾讯云数据库
|
|
|
|
# # 数据库B的连接信息;腾讯云数据库
|
|
|
|
db_b_config = {
|
|
|
|
# db_b_config = {
|
|
|
|
'host': '124.223.98.178',
|
|
|
|
# 'host': '124.223.98.178',
|
|
|
|
'user': 'root',
|
|
|
|
# 'user': 'root',
|
|
|
|
'password': '1qazse42W3',
|
|
|
|
# 'password': '1qazse42W3',
|
|
|
|
'db': 'mojin',
|
|
|
|
# 'db': 'mojin',
|
|
|
|
'charset': 'utf8mb4',
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
}
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
# try:
|
|
|
|
|
|
|
|
# # 连接数据库A
|
|
|
|
|
|
|
|
# db_a_conn = pymysql.connect(**db_a_config)
|
|
|
|
|
|
|
|
# db_a_cursor = db_a_conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 连接数据库B
|
|
|
|
|
|
|
|
# db_b_conn = pymysql.connect(**db_b_config)
|
|
|
|
|
|
|
|
# db_b_cursor = db_b_conn.cursor()
|
|
|
|
# 连接数据库A
|
|
|
|
# 连接数据库A
|
|
|
|
db_a_conn = pymysql.connect(**db_a_config)
|
|
|
|
db_a_conn = db_conn_a
|
|
|
|
db_a_cursor = db_a_conn.cursor()
|
|
|
|
db_a_cursor = dbcursor_a
|
|
|
|
|
|
|
|
|
|
|
|
# 连接数据库B
|
|
|
|
# 连接数据库B
|
|
|
|
db_b_conn = pymysql.connect(**db_b_config)
|
|
|
|
db_b_conn = db_conn_b
|
|
|
|
db_b_cursor = db_b_conn.cursor()
|
|
|
|
db_b_cursor = dbcursor_b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trans_date = trade_date
|
|
|
|
|
|
|
|
|
|
|
|
stock_basic_map = {}
|
|
|
|
stock_basic_map = {}
|
|
|
|
|
|
|
|
|
|
|
|
#查询交易日数据 更新数据到 8月9日
|
|
|
|
#查询交易日数据 更新数据到 8月9日
|
|
|
|
sql_trade_qurey = 'select date,week,trade from trade_dates where trade = %s and date > "2023-08-09"'
|
|
|
|
sql_trade_qurey = 'select date,week,trade from trade_dates where trade = %s and date > %s'
|
|
|
|
sql_trade = "trading"
|
|
|
|
sql_trade = "trading"
|
|
|
|
db_a_cursor.execute(sql_trade_qurey,sql_trade)
|
|
|
|
db_a_cursor.execute(sql_trade_qurey,(sql_trade,trade_date))
|
|
|
|
trading_dates = db_a_cursor.fetchall()
|
|
|
|
trading_dates = db_a_cursor.fetchall()
|
|
|
|
|
|
|
|
|
|
|
|
#查询东财基础数据
|
|
|
|
#查询东财基础数据
|
|
|
|
@ -174,6 +184,70 @@ try:
|
|
|
|
|
|
|
|
|
|
|
|
print("数据传输完成!")
|
|
|
|
print("数据传输完成!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# except Exception as e:
|
|
|
|
|
|
|
|
# print(f"出现错误:{e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# finally:
|
|
|
|
|
|
|
|
# # 关闭连接
|
|
|
|
|
|
|
|
# if db_a_cursor:
|
|
|
|
|
|
|
|
# db_a_cursor.close()
|
|
|
|
|
|
|
|
# if db_a_conn:
|
|
|
|
|
|
|
|
# db_a_conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if db_b_cursor:
|
|
|
|
|
|
|
|
# db_b_cursor.close()
|
|
|
|
|
|
|
|
# if db_b_conn:
|
|
|
|
|
|
|
|
# db_b_conn.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
# #数据库A的连接信息;NAS数据库
|
|
|
|
|
|
|
|
# db_a_config = {
|
|
|
|
|
|
|
|
# 'host': '192.168.0.222',
|
|
|
|
|
|
|
|
# 'user': 'root',
|
|
|
|
|
|
|
|
# 'password': '1qazse42W3',
|
|
|
|
|
|
|
|
# 'db': 'ry',
|
|
|
|
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # 数据库B的连接信息;NAS数据库
|
|
|
|
|
|
|
|
# db_b_config = {
|
|
|
|
|
|
|
|
# 'host': '192.168.0.222',
|
|
|
|
|
|
|
|
# 'user': 'root',
|
|
|
|
|
|
|
|
# 'password': '1qazse42W3',
|
|
|
|
|
|
|
|
# 'db': 'mojin',
|
|
|
|
|
|
|
|
# 'charset': 'utf8mb4',
|
|
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 数据库A的连接信息;腾讯云数据库
|
|
|
|
|
|
|
|
db_a_config = {
|
|
|
|
|
|
|
|
'host': '124.223.98.178',
|
|
|
|
|
|
|
|
'user': 'root',
|
|
|
|
|
|
|
|
'password': '1qazse42W3',
|
|
|
|
|
|
|
|
'db': 'ry',
|
|
|
|
|
|
|
|
'charset': 'utf8mb4',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 数据库B的连接信息;腾讯云数据库
|
|
|
|
|
|
|
|
db_b_config = {
|
|
|
|
|
|
|
|
'host': '124.223.98.178',
|
|
|
|
|
|
|
|
'user': 'root',
|
|
|
|
|
|
|
|
'password': '1qazse42W3',
|
|
|
|
|
|
|
|
'db': 'mojin',
|
|
|
|
|
|
|
|
'charset': 'utf8mb4',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
# 连接数据库A
|
|
|
|
|
|
|
|
db_a_conn = pymysql.connect(**db_a_config)
|
|
|
|
|
|
|
|
db_a_cursor = db_a_conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 连接数据库B
|
|
|
|
|
|
|
|
db_b_conn = pymysql.connect(**db_b_config)
|
|
|
|
|
|
|
|
db_b_cursor = db_b_conn.cursor()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trade_day = '2023-08-09'
|
|
|
|
|
|
|
|
toTransNewRecordData(db_a_conn,db_a_cursor,db_b_conn,db_b_cursor,trade_day)
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
print(f"出现错误:{e}")
|
|
|
|
print(f"出现错误:{e}")
|
|
|
|
|
|
|
|
|
|
|
|
@ -188,3 +262,5 @@ finally:
|
|
|
|
db_b_cursor.close()
|
|
|
|
db_b_cursor.close()
|
|
|
|
if db_b_conn:
|
|
|
|
if db_b_conn:
|
|
|
|
db_b_conn.close()
|
|
|
|
db_b_conn.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
main()
|