日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql load 占位符_Mysql占位符插入

發(fā)布時(shí)間:2023/12/19 数据库 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql load 占位符_Mysql占位符插入 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

#-*- coding: utf-8 -*-

importrequestsfrom bs4 importBeautifulSoupimportlxmlimportjsonimportreimporttimeimporttushare as tsimportpandas as pdimportpymysqlfrom sqlalchemy importcreate_engine

pymysql.install_as_MySQLdb()defTstockbasic(conn):#調(diào)用stock_basic,獲取股票代碼、股票名稱、所屬行業(yè)、上市日期、上市場(chǎng)所

cursor=conn.cursor()#讀取數(shù)據(jù)庫(kù)已存儲(chǔ)數(shù)據(jù)

sql_stk_data = pd.read_sql("select ts_code from stk_basic_data",con=conn).values#創(chuàng)建空列表,存儲(chǔ)ts_code

code_list =[]

incount= upcount = fincount = fupcount =0

stk_basic= pro.stock_basic(list_status=‘L‘, fields=‘ts_code,symbol,name,industry,list_date,exchange‘)for index, row instk_basic.iterrows():#new_code = row[‘ts_code‘][7:]+row[‘ts_code‘][:6]

new_code = row[‘ts_code‘]

stk_code= row[‘symbol‘]

stk_name= row[‘name‘]

industry= row[‘industry‘]

list_date= row[‘list_date‘]

exchange= row[‘exchange‘]#code_list.append(new_code)

code_list.append(new_code[7:]+new_code[:6])#if new_code in sql_stk_data.values:

if new_code insql_stk_data:

sql= "update stk_basic_data set industry = ‘%s‘ where ts_code = ‘%s‘" %(industry,new_code)

cursor.execute(sql)

upcount+= 1

print(upcount)‘‘‘try:

cursor.execute(sql)

upcount +=1

print(upcount)

except:

fupcount +=1‘‘‘

else:

sql= "insert into stk_basic_data(ts_code,stk_code,stk_name,industry,list_date,exchange) values(‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘,‘%s‘)"%(new_code,stk_code,stk_name,industry,list_date,exchange)

cursor.execute(sql)try:

cursor.execute(sql)

incount+=1

print(incount)except:

fincount+=1

print("股票列表成功更新:%d 條數(shù)據(jù),更新失敗:%d條數(shù)據(jù)" %(upcount, fupcount))print("股票列表成功新增:%d 條數(shù)據(jù),新增失敗:%d條數(shù)據(jù)" %(incount, fincount))

conn.commit()

conn.close()returncode_listif __name__ == "__main__":#設(shè)置tushare社區(qū)token

ts.set_token(‘a(chǎn)c16b470869c5d82db5033ae9288f77b282d2b5519507d6d2c72fdd7‘)

pro=ts.pro_api()#創(chuàng)建數(shù)據(jù)庫(kù)連接

conn = pymysql.connect(host=‘127.0.0.1‘, port=3306, user=‘root‘, passwd=‘123456‘, database=‘quantitative_trading_data‘, charset=‘utf8‘)

engine= create_engine(‘mysql://root:[email?protected]/quantitative_trading_data?charset=utf8‘)#獲取當(dāng)前年月日,傳遞給各函數(shù)

current = time.strftime("%Y%m%d", time.localtime())#調(diào)用Tstockbasich獲取股票列表,并完成數(shù)據(jù)更新

code_list = Tstockbasic(conn)

總結(jié)

以上是生活随笔為你收集整理的mysql load 占位符_Mysql占位符插入的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。