-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathyesterday_zt_monitor.py
74 lines (58 loc) · 2.06 KB
/
yesterday_zt_monitor.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 matplotlib
matplotlib.use("Pdf")
from configure.settings import DBSelector,config_dict
import pandas as pd
import tushare as ts
from plot_line import plot_stock_line
from common.BaseService import BaseService
from configure.util import send_message_via_wechat
import fire
# 绘制k线图,今日涨停的k线图
class PlotYesterdayZT(BaseService):
def __init__(self):
super(PlotYesterdayZT, self).__init__('log/yester_zdt.log')
self.image_path = config_dict('data_path')
def get_data(self,table):
DB = DBSelector()
engine = DB.get_engine('db_zdt', 'qq')
try:
df = pd.read_sql(table, engine)
except Exception as e:
self.logger.error('table_name >>> {}'.format(table))
self.logger.error(e)
return None
else:
return df
def plot_yesterday_zt(self,api,type_name='zrzt', current=datetime.datetime.now().strftime('%Y%m%d')):
start_data = datetime.datetime.now() + datetime.timedelta(days=-200)
start_data=start_data.strftime('%Y-%m-%d')
table = f'{current}{type_name}'
df = self.get_data(table)
for i in range(len(df)):
code = df.iloc[i]['代码']
name = df.iloc[i]['名称']
plot_stock_line(api,code, name, table_type=type_name, current=current, root_path=self.image_path,start=start_data, save=True)
def main(current=None):
# current='20191016'
if current is None:
current = datetime.datetime.now().strftime('%Y%m%d')
if isinstance(current,int):
current=str(current)
app = PlotYesterdayZT()
api =ts.get_apis()
for plot_type in ['zrzt', 'zdt']:
try:
app.plot_yesterday_zt(api,plot_type, current=current)
except Exception as e:
print(plot_type,'error')
print(e)
send_message_via_wechat('zdt_plot 出错')
continue
ts.close_apis(conn=api)
if __name__ == '__main__':
fire.Fire(main)