更新港资股票数据

重新更新数据

import pandas as pd
from sqlalchemy import create_engine
import tushare as ts
import datetime
import pymysql
import time
engine = create_engine('mysql+pymysql://****:*****@118.190.144.192/ts_gp?charset=utf8')
ts.set_token('******')
pro = ts.pro_api()
today=datetime.date.today()#今天
yesterday = today - datetime.timedelta(days=1)#昨天
yesterday_gs=yesterday.strftime("%Y%m%d")#格式化日期为YYYYMMDD
print(yesterday_gs)#昨天
sql_gz_trade_date = """SELECT DISTINCT t.trade_date FROM gz_mr_cgqk t where t.trade_date> '20181231'"""
data_gz_trade_date = pd.read_sql(sql_gz_trade_date, engine)
db = pymysql.connect(host="118.190.144.192", user="****", passwd="****", db="ts_gp", charset="utf8")
cursor = db.cursor()
for trade_date in data_gz_trade_date.values:
    print(trade_date[0])
    cursor.execute('call gz_hy_zj_q3(%s)', (trade_date[0]))
    db.commit()
db.close()
原文地址:https://www.cnblogs.com/liguangao/p/10659533.html