mns-scheduler 1.4.3.3__py3-none-any.whl → 1.4.4.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mns-scheduler might be problematic. Click here for more details.

Files changed (39) hide show
  1. mns_scheduler/{company_info/announce → auto_da_ban}/__init__.py +1 -1
  2. mns_scheduler/auto_da_ban/auto_da_ban_service.py +87 -0
  3. mns_scheduler/company_info/clean/company_info_clean_api.py +37 -16
  4. mns_scheduler/company_info/{base → common}/__init__.py +1 -1
  5. mns_scheduler/company_info/common/company_common_query_service.py +45 -0
  6. mns_scheduler/company_info/constant/company_constant_data.py +60 -49
  7. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +1 -0
  8. mns_scheduler/company_info/{remark → sync}/__init__.py +1 -1
  9. mns_scheduler/company_info/sync/company_info_set_service.py +208 -0
  10. mns_scheduler/company_info/sync/sync_company_info_task.py +203 -0
  11. mns_scheduler/company_info/task/__init__.py +7 -0
  12. mns_scheduler/company_info/{announce/company_announce_sync_service.py → task/company_announce_info_task.py} +25 -13
  13. mns_scheduler/company_info/task/company_base_info_task.py +64 -0
  14. mns_scheduler/company_info/{base/sync_company_product_area_industry.py → task/company_business_info_task.py} +33 -17
  15. mns_scheduler/company_info/task/company_hold_info_task.py +66 -0
  16. mns_scheduler/company_info/task/company_industry_info_task.py +167 -0
  17. mns_scheduler/company_info/task/company_total_task.py +69 -0
  18. mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +3 -3
  19. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +1 -1
  20. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +7 -2
  21. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +7 -57
  22. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +14 -25
  23. mns_scheduler/irm/stock_irm_cninfo_service.py +32 -26
  24. mns_scheduler/irm/stock_question_id_service.py +159 -0
  25. mns_scheduler/trade/auto_login/trader_auto_service.py +2 -1
  26. mns_scheduler/trade/task/trader_task_service.py +13 -2
  27. mns_scheduler/zb/stock_zb_pool_sync.py +1 -1
  28. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +217 -126
  29. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +1 -1
  30. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +4 -1
  31. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +1 -1
  32. mns_scheduler/zz_task/data_sync_task.py +30 -36
  33. {mns_scheduler-1.4.3.3.dist-info → mns_scheduler-1.4.4.5.dist-info}/METADATA +1 -1
  34. {mns_scheduler-1.4.3.3.dist-info → mns_scheduler-1.4.4.5.dist-info}/RECORD +36 -29
  35. mns_scheduler/company_info/base/sync_company_base_info_api.py +0 -531
  36. mns_scheduler/company_info/base/sync_company_hold_info_api.py +0 -37
  37. mns_scheduler/company_info/remark/company_remark_info_sync.py +0 -46
  38. {mns_scheduler-1.4.3.3.dist-info → mns_scheduler-1.4.4.5.dist-info}/WHEEL +0 -0
  39. {mns_scheduler-1.4.3.3.dist-info → mns_scheduler-1.4.4.5.dist-info}/top_level.txt +0 -0
@@ -1,531 +0,0 @@
1
- import os
2
- import sys
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 17
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
-
9
- from datetime import datetime
10
- import pandas as pd
11
- from loguru import logger
12
- import mns_common.api.ths.concept.web.ths_company_info_web as ths_company_info_web
13
- import mns_common.component.em.em_stock_info_api as em_stock_info_api
14
- import mns_common.component.common_service_fun_api as common_service_fun_api
15
- import mns_common.component.concept.ths_concept_common_service_api as ths_concept_common_service_api
16
- from mns_common.db.MongodbUtil import MongodbUtil
17
- import mns_common.api.kpl.symbol.kpl_real_time_quotes_api as kpl_real_time_quotes_api
18
- import mns_common.utils.data_frame_util as data_frame_util
19
- import mns_common.api.kpl.constant.kpl_constant as kpl_constant
20
- import mns_common.component.company.company_common_service_api as company_common_service_api
21
- import mns_common.component.k_line.common.k_line_common_service_api as k_line_common_service_api
22
- import mns_common.constant.db_name_constant as db_name_constant
23
- from functools import lru_cache
24
- import mns_scheduler.company_info.base.sync_company_hold_info_api as sync_company_hold_info_api
25
-
26
- mongodb_util = MongodbUtil('27017')
27
- # 分页大小
28
- MAX_PAGE_NUMBER = 2000
29
- import threading
30
-
31
- # 定义一个全局锁,用于保护 result 变量的访问
32
- result_lock = threading.Lock()
33
- # 初始化 result 变量为一个空的 Pandas DataFrame
34
- result = []
35
-
36
-
37
- # 同步公司基本信息
38
-
39
- def sync_company_base_info(symbol_list):
40
- global result
41
- result = []
42
- create_index()
43
- east_money_stock_info = get_east_money_stock_info()
44
- east_money_stock_info = east_money_stock_info.sort_values(by=['list_date'], ascending=False)
45
-
46
- de_listed_stock_list = company_common_service_api.get_de_list_company()
47
- east_money_stock_info = east_money_stock_info.loc[~(
48
- east_money_stock_info['symbol'].isin(de_listed_stock_list))]
49
- east_money_stock_info = common_service_fun_api.exclude_ts_symbol(east_money_stock_info)
50
- east_money_stock_info = east_money_stock_info.loc[~((east_money_stock_info['industry'] == '-')
51
- & (east_money_stock_info['now_price'] == 0))]
52
-
53
- east_money_stock_info = common_service_fun_api.total_mv_classification(east_money_stock_info)
54
- east_money_stock_info = common_service_fun_api.classify_symbol(east_money_stock_info)
55
-
56
- # 将日期数值转换为日期时间格式
57
- east_money_stock_info['list_date_01'] = pd.to_datetime(east_money_stock_info['list_date'], format='%Y%m%d')
58
-
59
- # 开盘啦实时数据
60
- kpl_real_time_quotes = kpl_real_time_quotes_api.get_kpl_real_time_quotes()
61
-
62
- if symbol_list is not None:
63
- east_money_stock_info = east_money_stock_info.loc[east_money_stock_info['symbol'].isin(symbol_list)]
64
- count = east_money_stock_info.shape[0]
65
- page_number = round(count / MAX_PAGE_NUMBER, 0) + 1
66
- page_number = int(page_number)
67
- threads = []
68
-
69
- exist_company_df = mongodb_util.find_all_data(db_name_constant.COMPANY_INFO)
70
-
71
- # 创建多个线程来获取数据
72
- for page in range(page_number): # 0到100页
73
- end_count = (page + 1) * MAX_PAGE_NUMBER
74
- begin_count = page * MAX_PAGE_NUMBER
75
- page_df = east_money_stock_info.iloc[begin_count:end_count]
76
- thread = threading.Thread(target=single_thread_sync_company_info,
77
- args=(page_df, kpl_real_time_quotes, exist_company_df))
78
- threads.append(thread)
79
- thread.start()
80
-
81
- # 等待所有线程完成
82
- for thread in threads:
83
- thread.join()
84
-
85
- fail_df = east_money_stock_info.loc[east_money_stock_info['symbol'].isin(result)]
86
- single_thread_sync_company_info(fail_df, kpl_real_time_quotes, exist_company_df)
87
-
88
-
89
- def get_east_money_stock_info():
90
- all_real_time_quotes = em_stock_info_api.get_a_stock_info()
91
- all_real_time_quotes = all_real_time_quotes[['symbol',
92
- 'name',
93
- "now_price",
94
- 'total_mv',
95
- 'flow_mv',
96
- 'pe_ttm',
97
- 'sz_sh',
98
- 'area',
99
- 'pb',
100
- 'list_date',
101
- 'ROE',
102
- 'total_share',
103
- 'flow_share',
104
- 'industry',
105
- 'amount',
106
- "hk_stock_code",
107
- "hk_stock_name",
108
- 'concept']]
109
-
110
- return all_real_time_quotes
111
-
112
-
113
- def single_thread_sync_company_info(east_money_stock_info,
114
- kpl_real_time_quotes, exist_company_df):
115
- global result
116
- fail_list = []
117
- for company_one in east_money_stock_info.itertuples():
118
- try:
119
- # 同步公司控股子公司信息 异步执行
120
- sync_company_hold_info_api.sync_company_hold_info(company_one.symbol)
121
-
122
- company_info_type = ths_company_info_web.get_company_info_detail(company_one.symbol)
123
- company_info_type = set_kzz_debt(company_info_type, company_one.symbol)
124
- company_info_type['first_industry_code'] = company_info_type['hycode'].apply(
125
- lambda x: x[1:3] + '0000')
126
- company_info_type['second_industry_code'] = company_info_type['hy2code'].apply(
127
- lambda x: x[1:5] + '00')
128
- company_info_type['third_industry_code'] = company_info_type['hy3code'].apply(
129
- lambda x: x[1:7])
130
- # company_info_type['main_business_list'] = company_info_type['main_business_list']
131
- # company_info_type['most_profitable_business'] = company_info_type['most_profitable_business']
132
- # company_info_type['most_profitable_business_rate'] = company_info_type['most_profitable_business_rate']
133
- # company_info_type['most_profitable_business_profit'] = company_info_type['most_profitable_business_profit']
134
- #
135
- company_info_type['first_sw_industry'] = company_info_type['hy']
136
- company_info_type['second_sw_industry'] = company_info_type['hy2']
137
- company_info_type['third_sw_industry'] = company_info_type['hy3']
138
- # 保存申万行业信息
139
- save_sw_data(company_info_type)
140
-
141
- company_info_type['_id'] = company_one.symbol
142
-
143
- company_info_type['name'] = company_one.name
144
-
145
- company_info_type['em_industry'] = company_one.industry
146
- company_info_type['em_concept'] = company_one.concept
147
-
148
- company_info_type['hk_stock_code'] = company_one.hk_stock_code
149
- company_info_type['hk_stock_name'] = company_one.hk_stock_name
150
-
151
- company_info_type['now_price'] = company_one.now_price
152
- company_info_type['total_share'] = company_one.total_share
153
- company_info_type['flow_share'] = company_one.flow_share
154
- company_info_type['total_mv'] = company_one.total_mv
155
- company_info_type['flow_mv'] = company_one.flow_mv
156
- company_info_type['area'] = company_one.area
157
- company_info_type['list_date'] = company_one.list_date
158
- now_date = datetime.now()
159
- # 计算日期差值 距离现在上市时间
160
- company_info_type['diff_days'] = (now_date - company_one.list_date_01).days
161
-
162
- company_info_type['pe_ttm'] = company_one.pe_ttm
163
- company_info_type['pb'] = company_one.pb
164
- company_info_type['ROE'] = company_one.ROE
165
- company_info_type['flow_mv_sp'] = company_one.flow_mv_sp
166
- company_info_type['total_mv_sp'] = company_one.total_mv_sp
167
- company_info_type['flow_mv_level'] = company_one.flow_mv_level
168
- company_info_type['classification'] = company_one.classification
169
-
170
- now_date = datetime.now()
171
- str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
172
-
173
- now_str_day = now_date.strftime('%Y-%m-%d')
174
- company_info_type['sync_date'] = str_now_date
175
-
176
- result_dict = calculate_circulation_ratio(company_one.symbol, now_str_day)
177
-
178
- company_info_type['mv_circulation_ratio'] = result_dict['mv_circulation_ratio']
179
- company_info_type['qfii_type'] = result_dict['qfii_type']
180
- company_info_type['qfii_number'] = result_dict['qfii_number']
181
- company_info_type['share_holder_sync_day'] = result_dict['share_holder_sync_day']
182
-
183
- # 获取同花顺最新概念
184
- company_info_type = ths_concept_common_service_api.set_ths_concept(company_one.symbol, company_info_type)
185
-
186
- fix_symbol_industry_df = company_constant_data.get_fix_symbol_industry()
187
- if company_one.symbol in list(fix_symbol_industry_df['symbol']):
188
- # fix sw_industry
189
- company_info_type = company_constant_data.fix_symbol_industry(company_info_type, company_one.symbol)
190
-
191
- # todo fix industry
192
- company_info_type['industry'] = company_info_type['second_sw_industry']
193
- company_info_type['amount'] = company_one.amount
194
-
195
- company_info_type['kpl_plate_list_info'] = '-'
196
- company_info_type['kpl_plate_name'] = '-'
197
- company_info_type['kpl_most_relative_name'] = '-'
198
- now_date = datetime.now()
199
- str_day = now_date.strftime('%Y-%m-%d')
200
- deal_days = k_line_common_service_api.get_deal_days(str_day, company_one.symbol)
201
- company_info_type['deal_days'] = deal_days
202
-
203
- # 设置年报信息
204
- company_info_type = get_recent_year_income(company_one.symbol, company_info_type, exist_company_df)
205
-
206
- try:
207
- if data_frame_util.is_not_empty(kpl_real_time_quotes):
208
- kpl_real_time_quotes_one = kpl_real_time_quotes.loc[
209
- kpl_real_time_quotes['symbol'] == company_one.symbol]
210
-
211
- if data_frame_util.is_not_empty(kpl_real_time_quotes_one):
212
- company_info_type['kpl_plate_name'] = list(kpl_real_time_quotes_one['plate_name_list'])[0]
213
- company_info_type['kpl_most_relative_name'] = \
214
- list(kpl_real_time_quotes_one['most_relative_name'])[
215
- 0]
216
- company_info_type = set_kpl_data(kpl_real_time_quotes_one, company_info_type, company_one)
217
-
218
- if bool(1 - ("kpl_plate_name" in company_info_type.columns)) or bool(
219
- 1 - ("kpl_most_relative_name" in company_info_type.columns)):
220
- company_info_type['kpl_plate_name'] = ""
221
- company_info_type['kpl_most_relative_name'] = ""
222
- except BaseException as e:
223
- logger.warning("设置开盘啦数据异常:{},{}", company_one.symbol, e)
224
-
225
- company_info_type = company_constant_data.filed_sort(company_info_type)
226
- mongodb_util.save_mongo(company_info_type.copy(), 'company_info_base')
227
- logger.info("同步公司信息完成:{}", company_one.symbol + '-' + company_one.name)
228
- except BaseException as e:
229
- fail_list.append(company_one.symbol)
230
- logger.error("同步公司信息发生异常:{},{}", company_one.symbol, e)
231
- with result_lock:
232
- # 使用锁来保护 result 变量的访问,将每页的数据添加到结果中
233
- result = fail_list
234
-
235
-
236
- # 计算实际流通比例
237
- def calculate_circulation_ratio(symbol, now_str_day):
238
- query = {"symbol": symbol}
239
- stock_gdfx_free_top_1 = mongodb_util.descend_query(query, 'stock_gdfx_free_top_10', "period", 1)
240
- if stock_gdfx_free_top_1.shape[0] == 0:
241
- mv_circulation_ratio = 1
242
- qfii_number = 0
243
- qfii_type = 'A股'
244
- share_holder_sync_day = now_str_day
245
- else:
246
- period_time = list(stock_gdfx_free_top_1['period'])[0]
247
-
248
- query_free = {'symbol': symbol, 'period': period_time}
249
- stock_gdfx_free_top_10 = mongodb_util.find_query_data('stock_gdfx_free_top_10', query_free)
250
-
251
- stock_gdfx_free_top_10['shares_number_str'] = stock_gdfx_free_top_10['shares_number'].astype(str)
252
-
253
- stock_gdfx_free_top_10['id_key'] = stock_gdfx_free_top_10['symbol'] + '_' + stock_gdfx_free_top_10[
254
- 'period'] + '_' + stock_gdfx_free_top_10.shares_number_str
255
-
256
- stock_gdfx_free_top_10.drop_duplicates('id_key', keep='last', inplace=True)
257
-
258
- # 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
259
- stock_gdfx_free_top_10['is_hk'] = stock_gdfx_free_top_10['shareholder_name'].apply(
260
- lambda shareholder_name: "HK" if shareholder_name.startswith('香港中央结算') or shareholder_name.startswith(
261
- 'HKSCC') else "A")
262
-
263
- # 持股大于5% 减持需要发公告
264
- # 排除香港结算公司不发公共 小于5%减持不用发公告
265
- # 香港中央结算 HKSCC
266
- stock_free_top_greater_than_5 = stock_gdfx_free_top_10.loc[
267
- (stock_gdfx_free_top_10['circulation_ratio'] >= 5) & (stock_gdfx_free_top_10['is_hk'] == 'A')]
268
-
269
- stock_free_qfii = stock_gdfx_free_top_10.loc[stock_gdfx_free_top_10['shareholder_nature'] == 'QFII']
270
-
271
- share_holder_sync_day = list(stock_gdfx_free_top_10['create_day'])[0]
272
-
273
- # qfii 数量
274
- qfii_number = stock_free_qfii.shape[0]
275
- # qfii 类型
276
- qfii_type = set_qfii_type(qfii_number, stock_free_qfii.copy())
277
-
278
- circulation_ratio = sum(stock_free_top_greater_than_5['circulation_ratio'])
279
- mv_circulation_ratio = round((100 - circulation_ratio) / 100, 2)
280
- # 防止错误数据
281
- if mv_circulation_ratio < 0:
282
- mv_circulation_ratio = 1
283
-
284
- result_dict = {
285
- 'mv_circulation_ratio': mv_circulation_ratio,
286
- 'qfii_type': qfii_type,
287
- 'qfii_number': qfii_number,
288
- 'share_holder_sync_day': share_holder_sync_day
289
-
290
- }
291
- return result_dict
292
-
293
-
294
- def set_qfii_type(qfii_number, stock_free_qfii):
295
- if qfii_number > 0:
296
- stock_free_qfii['new_change'] = stock_free_qfii['change']
297
- stock_free_qfii.loc[stock_free_qfii['change_ratio'] == 0, 'new_change'] = 0
298
- stock_free_qfii.loc[stock_free_qfii['change'] == '新进', 'new_change'] = \
299
- stock_free_qfii['shares_number']
300
- stock_free_qfii['new_change'] = stock_free_qfii['new_change'].astype(float)
301
-
302
- stock_free_qfii_new_in = stock_free_qfii.loc[stock_free_qfii['change'] == '新进']
303
- if data_frame_util.is_not_empty(stock_free_qfii_new_in):
304
- qfii_type = 1
305
- return qfii_type
306
-
307
- stock_free_qfii_add = stock_free_qfii.loc[
308
- (~stock_free_qfii['change'].isin(['不变', '新进'])) & (stock_free_qfii['new_change'] > 0)]
309
-
310
- if data_frame_util.is_not_empty(stock_free_qfii_add):
311
- qfii_type = 2
312
- return qfii_type
313
-
314
- stock_free_qfii_not_change = stock_free_qfii.loc[stock_free_qfii['change'] == '不变']
315
-
316
- if data_frame_util.is_not_empty(stock_free_qfii_not_change):
317
- qfii_type = 3
318
- return qfii_type
319
-
320
- stock_free_qfii_reduce = stock_free_qfii.loc[
321
- (~stock_free_qfii['change'].isin(['不变', '新进'])) & (stock_free_qfii['new_change'] < 0)]
322
-
323
- if data_frame_util.is_not_empty(stock_free_qfii_reduce):
324
- qfii_type = 4
325
- return qfii_type
326
- else:
327
- return 0
328
-
329
-
330
- def create_index():
331
- mongodb_util.create_index('company_info',
332
- [("classification", 1)])
333
- mongodb_util.create_index('company_info',
334
- [("industry", 1)])
335
- mongodb_util.create_index('company_info',
336
- [("flow_mv", 1)])
337
- mongodb_util.create_index('company_info',
338
- [("list_date", 1)])
339
- mongodb_util.create_index('company_info',
340
- [("symbol", 1)])
341
-
342
-
343
- def set_kpl_data(kpl_real_time_quotes_one, company_info_type, company_one):
344
- if data_frame_util.is_not_empty(kpl_real_time_quotes_one):
345
- company_info_type['kpl_plate_name'] = list(kpl_real_time_quotes_one['plate_name_list'])[0]
346
- company_info_type['kpl_most_relative_name'] = list(kpl_real_time_quotes_one['most_relative_name'])[
347
- 0]
348
- symbol = company_one.symbol
349
-
350
- query = {'symbol': symbol, "index_class": kpl_constant.FIRST_INDEX}
351
- kpl_best_choose_index_detail = mongodb_util.find_query_data('kpl_best_choose_index_detail', query)
352
- if data_frame_util.is_not_empty(kpl_best_choose_index_detail):
353
- kpl_best_choose_index_detail = kpl_best_choose_index_detail[[
354
- "plate_code",
355
- "plate_name",
356
- "first_plate_code",
357
- "first_plate_name",
358
- "index_class"
359
- ]]
360
-
361
- # 去除空格
362
- kpl_best_choose_index_detail['plate_name'] = kpl_best_choose_index_detail['plate_name'].str.replace(' ', '')
363
- # 去除空格
364
- kpl_best_choose_index_detail['first_plate_name'] = kpl_best_choose_index_detail[
365
- 'first_plate_name'].str.replace(' ', '')
366
-
367
- company_info_type.loc[:, 'kpl_plate_list_info'] = kpl_best_choose_index_detail.to_string(index=False)
368
- return company_info_type
369
-
370
-
371
- # 获取可转债信息
372
- @lru_cache(maxsize=None)
373
- def get_kzz_debt_info():
374
- query = {}
375
- kzz_debt_info_df = mongodb_util.find_query_data(db_name_constant.KZZ_DEBT_INFO, query)
376
- kzz_debt_info_df = kzz_debt_info_df[[
377
- 'symbol',
378
- 'name',
379
- 'stock_code',
380
- 'apply_date',
381
- 'list_date',
382
- 'due_date'
383
- ]]
384
- return kzz_debt_info_df
385
-
386
-
387
- def set_kzz_debt(df, symbol):
388
- kzz_debt_info_df_all = get_kzz_debt_info()
389
- kzz_debt_info_df = kzz_debt_info_df_all.loc[kzz_debt_info_df_all['stock_code'] == symbol]
390
- df.loc[:, 'kzz_debt_list'] = ''
391
- if data_frame_util.is_not_empty(kzz_debt_info_df):
392
- kzz_debt_info_df_list = kzz_debt_info_df.to_dict(orient='records')
393
- df.at[0, 'kzz_debt_list'] = kzz_debt_info_df_list
394
- return df
395
-
396
-
397
- # 保存申万行业分类
398
- def save_sw_data(company_info_type):
399
- now_date = datetime.now()
400
- hour = now_date.hour
401
- if hour <= 15:
402
- return company_info_type
403
- first_sw_info = company_info_type[[
404
- 'first_sw_industry',
405
- 'first_industry_code'
406
- ]].copy()
407
-
408
- first_sw_info.loc[:, "industry_code"] = first_sw_info['first_industry_code']
409
- first_sw_info.loc[:, "_id"] = first_sw_info['first_industry_code']
410
- first_sw_info.loc[:, "second_sw_industry"] = 0
411
- first_sw_info.loc[:, "third_sw_industry"] = 0
412
- first_sw_info.loc[:, "second_industry_code"] = 0
413
- first_sw_info.loc[:, "third_industry_code"] = 0
414
- first_sw_info = first_sw_info[[
415
- "_id",
416
- "industry_code",
417
- 'first_industry_code',
418
- 'first_sw_industry',
419
- 'second_industry_code',
420
- 'second_sw_industry',
421
- 'third_industry_code',
422
- 'third_sw_industry'
423
- ]]
424
- mongodb_util.save_mongo(first_sw_info, 'sw_industry')
425
-
426
- second_sw_info = company_info_type[[
427
- 'first_industry_code',
428
- 'first_sw_industry',
429
- 'second_sw_industry',
430
- 'second_industry_code',
431
- ]].copy()
432
-
433
- second_sw_info.loc[:, "industry_code"] = second_sw_info['second_industry_code']
434
- second_sw_info.loc[:, "_id"] = second_sw_info['industry_code']
435
-
436
- second_sw_info.loc[:, "third_sw_industry"] = 0
437
- second_sw_info.loc[:, "third_sw_industry"] = 0
438
- second_sw_info.loc[:, "third_industry_code"] = 0
439
- second_sw_info = second_sw_info[[
440
- "_id",
441
- "industry_code",
442
- 'first_industry_code',
443
- 'first_sw_industry',
444
- 'second_industry_code',
445
- 'second_sw_industry',
446
- 'third_industry_code',
447
- 'third_sw_industry'
448
- ]]
449
- mongodb_util.save_mongo(second_sw_info, 'sw_industry')
450
-
451
- third_sw_info = company_info_type[[
452
- 'first_industry_code',
453
- 'first_sw_industry',
454
- 'second_industry_code',
455
- 'second_sw_industry',
456
- 'third_industry_code',
457
- 'third_sw_industry'
458
- ]].copy()
459
-
460
- third_sw_info.loc[:, "industry_code"] = third_sw_info['third_industry_code']
461
-
462
- third_sw_info.loc[:, "_id"] = third_sw_info['industry_code']
463
-
464
- third_sw_info = third_sw_info[[
465
- "_id",
466
- "industry_code",
467
- 'first_industry_code',
468
- 'first_sw_industry',
469
- 'second_industry_code',
470
- 'second_sw_industry',
471
- 'third_industry_code',
472
- 'third_sw_industry'
473
- ]]
474
- mongodb_util.save_mongo(third_sw_info, 'sw_industry')
475
-
476
-
477
- # 获取最近年报收入
478
- def get_recent_year_income(symbol, company_info_type, exist_company_df):
479
- now_date = datetime.now()
480
- hour = now_date.hour
481
- # if hour <= 15:
482
- # exist_company_one_df = exist_company_df.loc[exist_company_df['_id'] == symbol]
483
- # if data_frame_util.is_not_empty(exist_company_one_df):
484
- # company_info_type['operate_profit'] = list(exist_company_one_df['operate_profit'])[0]
485
- # company_info_type['total_operate_income'] = list(exist_company_one_df['total_operate_income'])[0]
486
- # if 'operate_date_name' in exist_company_one_df:
487
- # company_info_type['operate_date_name'] = list(exist_company_one_df['total_operate_income'])[0]
488
- # else:
489
- # company_info_type['operate_date_name'] = '暂无年报'
490
- # else:
491
- # company_info_type['operate_profit'] = 0
492
- # company_info_type['total_operate_income'] = 0
493
- # company_info_type['operate_date_name'] = '暂无年报'
494
- # return company_info_type
495
- query = {'symbol': symbol, "REPORT_TYPE": "年报"}
496
- em_stock_profit = mongodb_util.descend_query(query, db_name_constant.EM_STOCK_PROFIT, 'REPORT_DATE', 1)
497
- if data_frame_util.is_not_empty(em_stock_profit):
498
- company_info_type['operate_profit'] = list(em_stock_profit['OPERATE_PROFIT'])[0]
499
- company_info_type['operate_date_name'] = list(em_stock_profit['REPORT_DATE_NAME'])[0]
500
- total_operate_income = list(em_stock_profit['TOTAL_OPERATE_INCOME'])[0]
501
- # 金融机构大多收入计入在这个字段中
502
- if total_operate_income == 0:
503
- total_operate_income = list(em_stock_profit['OPERATE_INCOME'])[0]
504
-
505
- company_info_type['total_operate_income'] = total_operate_income
506
- else:
507
- company_info_type['operate_profit'] = 0
508
- company_info_type['total_operate_income'] = 0
509
- company_info_type['operate_date_name'] = '暂无年报'
510
- company_info_type['operate_profit'] = round(
511
- company_info_type['operate_profit'] / common_service_fun_api.HUNDRED_MILLION, 2)
512
- company_info_type['total_operate_income'] = round(
513
- company_info_type['total_operate_income'] / common_service_fun_api.HUNDRED_MILLION, 2)
514
- return company_info_type
515
-
516
-
517
- import mns_scheduler.company_info.constant.company_constant_data as company_constant_data
518
-
519
- if __name__ == '__main__':
520
- # sync_company_base_info()
521
- # fix_company_industry()
522
- # calculate_circu_ratio("601069")
523
- # sync_company_base_info()
524
- # 300293
525
- # sync_company_base_info(None)
526
- # new_company_info_update()
527
- # query = {"total_operate_income": 0}
528
- # un_report_company_info = mongodb_util.find_query_data(db_name_constant.COMPANY_INFO, query)
529
- # symbol_list = list(un_report_company_info['symbol'])
530
- sync_company_base_info(['920009'])
531
- sync_company_base_info(None)
@@ -1,37 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 17
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.api.ths.company.ths_company_info_api as ths_company_info_api
9
- import mns_common.component.cookie.cookie_info_service as cookie_info_service
10
- import mns_common.utils.data_frame_util as data_frame_util
11
- from mns_common.db.MongodbUtil import MongodbUtil
12
- import mns_common.constant.db_name_constant as db_name_constant
13
- from datetime import datetime
14
- from mns_common.utils.async_fun import async_fun
15
- from loguru import logger
16
-
17
- mongodb_util = MongodbUtil('27017')
18
-
19
-
20
- # 同步公司控股子公司信息
21
- @async_fun
22
- def sync_company_hold_info(symbol):
23
- try:
24
- ths_cookie = cookie_info_service.get_ths_cookie()
25
- company_hold_info_df = ths_company_info_api.get_company_hold_info(symbol, ths_cookie)
26
-
27
- now_date = datetime.now()
28
- sync_str_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
29
- if data_frame_util.is_not_empty(company_hold_info_df):
30
- company_hold_info_df['sync_str_date'] = sync_str_date
31
- mongodb_util.insert_mongo(company_hold_info_df, db_name_constant.COMPANY_HOLDING_INFO)
32
- except BaseException as e:
33
- logger.error("同步公司控股子公司信息:{},{}", symbol, e)
34
-
35
-
36
- if __name__ == '__main__':
37
- sync_company_hold_info('300085')
@@ -1,46 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 17
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.api.ths.concept.web.ths_company_info_web as ths_company_info_web
9
- import mns_common.component.em.em_stock_info_api as em_stock_info_api
10
- from mns_common.db.MongodbUtil import MongodbUtil
11
- import mns_common.utils.data_frame_util as data_frame_util
12
- import mns_common.constant.db_name_constant as db_name_constant
13
- import mns_common.component.company.company_common_service_api as company_common_service_api
14
- import mns_common.component.common_service_fun_api as common_service_fun_api
15
- from loguru import logger
16
-
17
- mongodb_util = MongodbUtil('27017')
18
-
19
-
20
- def sync_company_remark_info():
21
- east_money_stock_info = em_stock_info_api.get_a_stock_info()
22
- de_listed_stock_list = company_common_service_api.get_de_list_company()
23
- east_money_stock_info = east_money_stock_info.loc[~(
24
- east_money_stock_info['symbol'].isin(de_listed_stock_list))]
25
- east_money_stock_info = common_service_fun_api.exclude_ts_symbol(east_money_stock_info)
26
- east_money_stock_info = east_money_stock_info.loc[~((east_money_stock_info['industry'] == '-')
27
- & (east_money_stock_info['now_price'] == 0))]
28
-
29
- for stock_one in east_money_stock_info.itertuples():
30
- try:
31
- company_remark_info = ths_company_info_web.get_company_info(stock_one.symbol)
32
- company_remark_info['_id'] = stock_one.symbol
33
- company_remark_info['symbol'] = stock_one.symbol
34
- company_remark_info['remark'] = ''
35
- exist_company_remark_df = mongodb_util.find_query_data(db_name_constant.COMPANY_REMARK_INFO,
36
- query={"symbol": stock_one.symbol})
37
- if data_frame_util.is_not_empty(exist_company_remark_df):
38
- company_remark_info['remark'] = list(exist_company_remark_df['remark'])[0]
39
- mongodb_util.save_mongo(company_remark_info, db_name_constant.COMPANY_REMARK_INFO)
40
- except BaseException as e:
41
-
42
- logger.error("同步公司备注信息发生异常:{},{}", stock_one.symbol, e)
43
-
44
-
45
- if __name__ == '__main__':
46
- sync_company_remark_info()