1 Star 0 Fork 1

ichao1214 / stock

forked from rzxxysy / stock 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
maintaince_db.py 2.14 KB
一键复制 编辑 原始数据 按行查看 历史
Rockyzsu 提交于 2019-09-24 13:45 . update
# -*-coding=utf-8-*-
import datetime
import re
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: weigesysu@qq.com
'''
from settings import get_engine,get_mysql_conn
import pandas as pd
def clone_database():
local_db =get_mysql_conn('db_zdt',local=True)
cur = local_db.cursor()
cur.execute('show tables')
tables=cur.fetchall()
local_engine = get_engine('db_zdt',local=True)
dfs=[]
for table in tables:
try:
result =re.findall('(\d+)zdt$', table[0])
if result:
print(table[0])
current = result[0]
# d= datetime.datetime.strptime(current,'%Y%m%d').strftime('%Y-%m-%d')
# print(d)
df =pd.read_sql(table[0],local_engine,index_col='index')
# df['涨停日期']=d
df=df.rename(columns={'最后一次涨停时间A':'最后一次涨停时间','第一次涨停时间A':'第一次涨停时间'})
try:
print(df.head())
df.to_sql(table[0],local_engine,if_exists='replace')
except Exception as e:
print(e)
except Exception as e:
print(e)
print(table[0])
# dfs.append(pd.read_sql(table[0],local_engine))
# df= pd.concat(dfs)
# print(df.head())
def merge_database():
local_db =get_mysql_conn('db_zdt',local=True)
cur = local_db.cursor()
cur.execute('show tables')
tables=cur.fetchall()
local_engine = get_engine('db_zdt',local=True)
dfs=[]
for table in tables:
try:
result =re.findall('(\d+)zdt$', table[0])
if len(result)>0:
print(table[0])
df =pd.read_sql(table[0],local_engine,index_col='index')
dfs.append(df)
except Exception as e:
print(e)
print(table[0])
dfx= pd.concat(dfs)
print(dfx.head())
# ali_engine = get_engine(None,local=False)
local_engine_stock=get_engine('db_stock',local=True)
dfx.to_sql('tb_zdt',local_engine_stock,if_exists='replace')
if __name__=="__main__":
# clone_database()
merge_database()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ichao1214/stock.git
git@gitee.com:ichao1214/stock.git
ichao1214
stock
stock
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891