forked from Rockyzsu/stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaintaince_db.py
72 lines (64 loc) · 2.14 KB
/
maintaince_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*-coding=utf-8-*-
import datetime
import re
__author__ = 'Rocky'
'''
http://30daydo.com
Contact: [email protected]
'''
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()