-
Notifications
You must be signed in to change notification settings - Fork 0
/
Launcher.py
247 lines (178 loc) · 8.54 KB
/
Launcher.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import json
import os
import sys
import time
import numpy as np
import pysnowball as ball
import streamlit as st
import tushare as ts
from AnalyzeData import AnalyzeData
from DataUpgrade import DataUpgrade
from Utils import Utils
from C import C
from configparser import ConfigParser
import pandas as pd
def local_css(file_name):
with open(file_name) as f:
st.markdown('<style>{}</style>'.format(f.read()), unsafe_allow_html=True)
def add_color(table, column):
table[column] = table[column].map(
lambda x: f"<div class='bg_green'>{x}</div>" if (x is not None and x > 0) else f"<div class='bg_red'>{x}</div>")
def str_big_number(table, column):
table[column] = table[column].map(lambda x: Utils.str_of_num(x))
if __name__ == '__main__':
os.environ['NUMEXPR_MAX_THREADS'] = '8'
config = ConfigParser()
config.read('token.config')
ball.set_token(config.get('token', 'xueqiu')) # xq_a_token=XXXX
pro = ts.pro_api(config.get('token', 'tushare'))
st.set_page_config(layout="wide")
local_css("style.css")
date = time.strftime("%Y-%m-%d", time.localtime())
myStockWithName = [ # 自选股,跟踪个股研报,格式直接从雪球网页复制
'西藏旅游(SH:600749)', "千味央厨(SZ:001215)", "亚钾国际(SZ:000893)", "小熊电器(SZ:002959)",
"盐湖股份(SZ:000792)",
"杭萧钢构(SH:600477)", '中望软件(SH:688083)', '兴发集团(SH:600141)', '华大基因(SZ:300676)',
"雪人股份(SZ:002639)",
"牧高笛(SH:603908)", "燕京啤酒(SZ:000729)", "和远气体(SZ:002971)", "中体产业(SH:600158)", '中国船舶(SH:600150)',
'中无人机(SH:688297)',
'新强联(SZ:300850)', '奇安信-U(SH:688561)', "成都先导(SH:688222)", "洽洽食品(SZ:002557)", "农发种业(SH:600313)",
'东方电缆(SH:603606)', '东方财富(SZ:300059)', '沃森生物(SZ:300142)', '道恩股份(SZ:002838)',
'南模生物(SH:688265)', '君亭酒店(SZ:301073)'
]
myStock = {x[-7:-1] for x in myStockWithName}
if not os.path.exists(C.DATA_PATH):
os.mkdir(C.DATA_PATH)
# 更新基础数据
DataUpgrade.updateBK(ball)
DataUpgrade.updateStocks(pro)
elif len(sys.argv) > 1 and sys.argv[1] == 'bk':
DataUpgrade.updateBK(ball)
if not os.path.exists(C.CACHE_PATH):
os.mkdir(C.CACHE_PATH)
# ——————————————————————————————
# 板块涨跌
dfs = AnalyzeData.getBKs(ball)
chartData = AnalyzeData.getChart()
st.line_chart(chartData,x='date',y='X')
st.markdown(f"[打开个股研报](file:///{C.REPORT_PATH}{date}-个股/)")
st.markdown(f"[打开行业研报](file:///{C.REPORT_PATH}{date}-行业/)")
st.markdown(f"[打开宏观研报](file:///{C.REPORT_PATH}{date}-宏观/)")
st.write("")
st.markdown("### 自选今日财报:")
fReport = AnalyzeData.getFReport()
fReportTable = AnalyzeData.getStocksTable(ball, fReport)
add_color(fReportTable, 'percent')
add_color(fReportTable, 'current_year_percent')
str_big_number(fReportTable, 'amount')
st.write(fReportTable.to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今日涨幅前10板块:")
add_color(dfs[0], 'percent')
add_color(dfs[0], 'current_year_percent')
st.write(dfs[0].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今日跌幅前10板块:")
add_color(dfs[1], 'percent')
add_color(dfs[1], 'current_year_percent')
st.write(dfs[1].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今年涨幅前10板块:")
add_color(dfs[2], 'percent')
add_color(dfs[2], 'current_year_percent')
st.write(dfs[2].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今年跌幅前10板块:")
add_color(dfs[3], 'percent')
add_color(dfs[3], 'current_year_percent')
st.write(dfs[3].to_html(escape=False, index=False), unsafe_allow_html=True)
## 板块涨跌
## 个股涨跌
df_stocks = AnalyzeData.getStocks(ball)
st.write("")
st.markdown("### 今日涨幅前10个股(所有个股数据排除ST,下同):")
add_color(df_stocks[0], 'percent')
add_color(df_stocks[0], 'current_year_percent')
st.write(df_stocks[0].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今日跌幅前10个股:")
add_color(df_stocks[1], 'percent')
add_color(df_stocks[1], 'current_year_percent')
st.write(df_stocks[1].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今日成交额前10个股:")
add_color(df_stocks[2], 'percent')
add_color(df_stocks[2], 'current_year_percent')
str_big_number(df_stocks[2], 'amount')
st.write(df_stocks[2].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今日成交额后10个股(排除北交所):")
add_color(df_stocks[3], 'percent')
add_color(df_stocks[3], 'current_year_percent')
str_big_number(df_stocks[3], 'amount')
st.write(df_stocks[3].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今年涨幅前10个股:")
add_color(df_stocks[4], 'percent')
add_color(df_stocks[4], 'current_year_percent')
st.write(df_stocks[4].to_html(escape=False, index=False), unsafe_allow_html=True)
st.write("")
st.markdown("### 今年跌幅前10个股:")
add_color(df_stocks[5], 'percent')
add_color(df_stocks[5], 'current_year_percent')
st.write(df_stocks[5].to_html(escape=False, index=False), unsafe_allow_html=True)
## 个股涨跌
st.write("")
df_stocks_today = Utils.readCSVFromCache("today_stocks_" + date)
today_up = df_stocks_today[df_stocks_today.percent > 0].shape[0]
today_same = df_stocks_today[df_stocks_today.percent == 0].shape[0]
today_down = df_stocks_today[df_stocks_today.percent < 0].shape[0]
today_sum = today_up + today_same + today_down
st.markdown(
"### 今日上涨:" + str(today_up) + "(" + str(round(Utils.divFormat(today_up * 100, today_sum), 2)) + "%)"
+ ",横盘:" + str(today_same) + "(" + str(round(Utils.divFormat(today_same * 100, today_sum), 2)) + "%)"
+ ",下跌:" + str(today_down) + "(" + str(round(Utils.divFormat(today_down * 100, today_sum), 2)) + "%)"
)
st.markdown(
"### 涨幅中位数:" + str(round(np.median(df_stocks_today[df_stocks_today.percent > 0].percent), 2)) + "%"
+ ",跌幅中位数:" + str(round(np.median(df_stocks_today[df_stocks_today.percent < 0].percent), 2)) + "%"
)
st.markdown(
"### 涨幅超9.5%:" + str(df_stocks_today[df_stocks_today.percent > 9.5].shape[0])
+ ",跌幅超9.5%:" + str(df_stocks_today[df_stocks_today.percent < -9.5].shape[0])
)
# 测试折线图 开始
# st.line_chart(np.array(df_stocks_today[df_stocks_today.percent > 0].sort_values('percent').percent).tolist())
# st.line_chart(np.array(pd.DataFrame.abs(df_stocks_today[df_stocks_today.percent < 0].sort_values('percent', ascending=False).percent)).tolist())
# 测试折线图 结束
# ## 个股资金
# df_stocks = AnalyzeData.getCapitalAssort(ball)
#
# st.write("")
# st.markdown("### 今日流入前10个股:")
# st.write(df_stocks[0].to_html(escape=False, index=False), unsafe_allow_html=True)
#
# st.write("")
# st.markdown("### 今日流出前10个股:")
# st.write(df_stocks[1].to_html(escape=False, index=False), unsafe_allow_html=True)
#
# st.write("")
# st.markdown("### 今日大单前10个股:")
# st.write(df_stocks[2].to_html(escape=False, index=False), unsafe_allow_html=True)
#
# st.write("")
# st.markdown("### 今日大单后10个股:")
# st.write(df_stocks[3].to_html(escape=False, index=False), unsafe_allow_html=True)
#
# ## 个股资金
print('宏观研报...')
AnalyzeData.get_report(AnalyzeData.get_url(3), type=3) # 宏观
print('行业研报...')
AnalyzeData.get_report(AnalyzeData.get_url(1), type=1) # 行业
# AnalyzeData.get_report(AnalyzeData.get_url(1), type=1, keyword=['深度', '旅游']) # 行业
print('个股研报...')
AnalyzeData.get_report(AnalyzeData.get_url(0, ), type=0) # 个股
# 仅获取自选股个股研报
for code in myStock:
AnalyzeData.get_report(AnalyzeData.get_url(0, code=code), type=0) # 个股
print("执行完毕")