mns-scheduler 1.1.8.4__py3-none-any.whl → 1.4.5.7__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.
Files changed (139) hide show
  1. mns_scheduler/__init__.py +1 -3
  2. mns_scheduler/auto_da_ban/auto_da_ban_service.py +89 -0
  3. mns_scheduler/company_info/clean/__init__.py +1 -1
  4. mns_scheduler/company_info/clean/company_info_clean_api.py +62 -21
  5. mns_scheduler/company_info/common/company_common_query_service.py +45 -0
  6. mns_scheduler/company_info/constant/__init__.py +1 -1
  7. mns_scheduler/company_info/constant/company_constant_data.py +335 -224
  8. mns_scheduler/company_info/de_list_stock/__init__.py +1 -1
  9. mns_scheduler/company_info/de_list_stock/de_list_stock_service.py +1 -1
  10. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +134 -0
  11. mns_scheduler/company_info/sync/company_info_set_service.py +208 -0
  12. mns_scheduler/company_info/sync/sync_company_info_task.py +203 -0
  13. mns_scheduler/company_info/task/company_announce_info_task.py +77 -0
  14. mns_scheduler/company_info/task/company_base_info_task.py +64 -0
  15. mns_scheduler/company_info/task/company_business_info_task.py +177 -0
  16. mns_scheduler/company_info/task/company_hold_info_task.py +66 -0
  17. mns_scheduler/company_info/task/company_industry_info_task.py +167 -0
  18. mns_scheduler/company_info/task/company_total_task.py +69 -0
  19. mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
  20. mns_scheduler/concept/clean/ths_concept_clean_api.py +20 -4
  21. mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +23 -18
  22. mns_scheduler/concept/ths/common/ths_concept_update_common_api.py +4 -1
  23. mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +7 -7
  24. mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_new_index_api.py +9 -4
  25. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +2 -2
  26. mns_scheduler/db/col_move_service.py +3 -3
  27. mns_scheduler/db/script/__init__.py +1 -1
  28. mns_scheduler/db/script/col_move_script.py +1 -1
  29. mns_scheduler/db/script/db_move/__init__.py +7 -0
  30. mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
  31. mns_scheduler/db/script/sync/__init__.py +1 -1
  32. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +65 -4
  33. mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +80 -0
  34. mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
  35. mns_scheduler/db/script/update/__init__.py +7 -0
  36. mns_scheduler/db/script/update/update_col_field.py +36 -0
  37. mns_scheduler/finance/__init__.py +1 -1
  38. mns_scheduler/finance/em/__init__.py +7 -0
  39. mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +2 -2
  40. mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +27 -26
  41. mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +3 -3
  42. mns_scheduler/finance/{sync_financial_report_service_api.py → sync_financial_report_service_task.py} +80 -27
  43. mns_scheduler/finance/xue_qiu/__init__.py +7 -0
  44. mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
  45. mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
  46. mns_scheduler/hk/__init__.py +1 -1
  47. mns_scheduler/hk/hk_company_info_sync_service_api.py +4 -4
  48. mns_scheduler/hk/hk_industry_info_sync_service_api.py +3 -5
  49. mns_scheduler/industry/__init__.py +7 -0
  50. mns_scheduler/industry/ths/__init__.py +7 -0
  51. mns_scheduler/industry/ths/ths_industry_index_service.py +58 -0
  52. mns_scheduler/industry/ths/ths_industry_sync_service.py +68 -0
  53. mns_scheduler/irm/__init__.py +1 -1
  54. mns_scheduler/irm/api/__init__.py +1 -1
  55. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +8 -58
  56. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +15 -26
  57. mns_scheduler/irm/stock_irm_cninfo_service.py +43 -31
  58. mns_scheduler/irm/stock_question_id_service.py +169 -0
  59. mns_scheduler/k_line/clean/daily/__init__.py +1 -1
  60. mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +52 -6
  61. mns_scheduler/k_line/clean/daily/daily_k_line_service.py +7 -2
  62. mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
  63. mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -15
  64. mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
  65. mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +124 -26
  66. mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +2 -2
  67. mns_scheduler/k_line/common/__init__.py +7 -0
  68. mns_scheduler/k_line/common/k_line_common_api.py +188 -0
  69. mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
  70. mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
  71. mns_scheduler/k_line/{sync → month_week_daily}/bfq_k_line_sync.py +14 -29
  72. mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +11 -12
  73. mns_scheduler/k_line/sync_status/__init__.py +7 -0
  74. mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
  75. mns_scheduler/k_line/test/__init__.py +1 -1
  76. mns_scheduler/k_line/test/k_line_info_clean_his_data.py +14 -3
  77. mns_scheduler/k_line/year_quarter/__init__.py +7 -0
  78. mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
  79. mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +1 -2
  80. mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
  81. mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +5 -0
  82. mns_scheduler/lhb/__init__.py +1 -1
  83. mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
  84. mns_scheduler/open/__init__.py +1 -1
  85. mns_scheduler/open/sync_one_day_open_data_to_db_service.py +2 -3
  86. mns_scheduler/risk/__init__.py +1 -1
  87. mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +8 -2
  88. mns_scheduler/risk/financial/annual_report_audit_check_api.py +13 -3
  89. mns_scheduler/risk/financial/net_assets_check_api.py +21 -18
  90. mns_scheduler/risk/financial/profit_income_check_api.py +7 -2
  91. mns_scheduler/risk/financial_report_risk_check_api.py +1 -1
  92. mns_scheduler/risk/major_violations/register_and_investigate_stock_sync_api.py +1 -1
  93. mns_scheduler/risk/self/wei_pan_stock_api.py +1 -1
  94. mns_scheduler/risk/test/__init__.py +1 -1
  95. mns_scheduler/risk/test/fix_blask_list.py +4 -6
  96. mns_scheduler/risk/transactions/transactions_check_api.py +22 -4
  97. mns_scheduler/self_choose/__init__.py +1 -1
  98. mns_scheduler/self_choose/ths_self_choose_service.py +99 -43
  99. mns_scheduler/trade/auto_login/trader_auto_service.py +7 -4
  100. mns_scheduler/trade/auto_sell_service_api.py +4 -4
  101. mns_scheduler/trade/balance/__init__.py +7 -0
  102. mns_scheduler/trade/balance/ths_account_balance_service.py +7 -0
  103. mns_scheduler/trade/sync_position_api.py +39 -6
  104. mns_scheduler/trade/task/trader_task_service.py +38 -10
  105. mns_scheduler/trade/tfp/__init__.py +7 -0
  106. mns_scheduler/trade/tfp/stock_tfp_info_sync.py +56 -0
  107. mns_scheduler/zb/stock_zb_pool_sync.py +1 -16
  108. mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -2
  109. mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +1 -1
  110. mns_scheduler/zt/script/__init__.py +1 -1
  111. mns_scheduler/zt/script/fix_error_deal_day.py +41 -0
  112. mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -2
  113. mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
  114. mns_scheduler/zt/script/sync_now_higt_chg_zt.py +8 -7
  115. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +260 -83
  116. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +33 -90
  117. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +27 -13
  118. mns_scheduler/zz_task/compensation/__init__.py +0 -0
  119. mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
  120. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
  121. mns_scheduler/zz_task/data_sync_task.py +197 -103
  122. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.dist-info}/METADATA +1 -1
  123. mns_scheduler-1.4.5.7.dist-info/RECORD +176 -0
  124. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.dist-info}/WHEEL +1 -1
  125. mns_scheduler/2014-2015-test/2014_2015_chg_statistics.py +0 -87
  126. mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
  127. mns_scheduler/company_info/base/sync_company_base_info_api.py +0 -439
  128. mns_scheduler/company_info/base/sync_company_hold_info_api.py +0 -40
  129. mns_scheduler/company_info/remark/company_remark_info_sync.py +0 -46
  130. mns_scheduler/db/real_time_task_check.py +0 -84
  131. mns_scheduler/debt/kzz_bond_info_sync.py +0 -33
  132. mns_scheduler-1.1.8.4.dist-info/RECORD +0 -142
  133. /mns_scheduler/{2014-2015-test → auto_da_ban}/__init__.py +0 -0
  134. /mns_scheduler/company_info/{base → common}/__init__.py +0 -0
  135. /mns_scheduler/{big_deal → company_info/em_stock_info}/__init__.py +0 -0
  136. /mns_scheduler/company_info/{remark → sync}/__init__.py +0 -0
  137. /mns_scheduler/{debt → company_info/task}/__init__.py +0 -0
  138. /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
  139. {mns_scheduler-1.1.8.4.dist-info → mns_scheduler-1.4.5.7.dist-info}/top_level.txt +0 -0
@@ -1,439 +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.api.em.east_money_stock_v2_api as east_money_stock_v2_api
14
- import mns_scheduler.company_info.constant.company_constant_data as company_constant_data
15
- import mns_common.component.common_service_fun_api as common_service_fun_api
16
- import mns_common.component.concept.ths_concept_common_service_api as ths_concept_common_service_api
17
- from mns_common.db.MongodbUtil import MongodbUtil
18
- import mns_common.api.kpl.symbol.kpl_real_time_quotes_api as kpl_real_time_quotes_api
19
- import mns_common.utils.data_frame_util as data_frame_util
20
- import mns_common.api.kpl.constant.kpl_constant as kpl_constant
21
- import mns_common.component.company.company_common_service_api as company_common_service_api
22
- import mns_common.component.k_line.common.k_line_common_service_api as k_line_common_service_api
23
- import mns_common.constant.db_name_constant as db_name_constant
24
- from functools import lru_cache
25
- import mns_scheduler.company_info.base.sync_company_hold_info_api as sync_company_hold_info_api
26
-
27
- mongodb_util = MongodbUtil('27017')
28
- # 分页大小
29
- MAX_PAGE_NUMBER = 2000
30
- import threading
31
-
32
- # 定义一个全局锁,用于保护 result 变量的访问
33
- result_lock = threading.Lock()
34
- # 初始化 result 变量为一个空的 Pandas DataFrame
35
- result = []
36
-
37
-
38
- # 计算实际流通比例
39
- def calculate_circulation_ratio(symbol):
40
- query = {"symbol": symbol}
41
- stock_gdfx_free_top_10 = mongodb_util.descend_query(query, 'stock_gdfx_free_top_10', "period", 10)
42
- if stock_gdfx_free_top_10.shape[0] == 0:
43
- mv_circulation_ratio = 1
44
- else:
45
- # 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
46
- stock_gdfx_free_top_10['is_hk'] = stock_gdfx_free_top_10['shareholder_name'].apply(
47
- lambda shareholder_name: "HK" if shareholder_name.startswith('香港中央结算') or shareholder_name.startswith(
48
- 'HKSCC') else "A")
49
-
50
- # 持股大于5% # 排除香港结算公司 大于5%减持不用发公告 香港中央结算 HKSCC
51
- stock_gdfx_free_top_10 = stock_gdfx_free_top_10.loc[
52
- (stock_gdfx_free_top_10['circulation_ratio'] >= 5) & (stock_gdfx_free_top_10['is_hk'] == 'A')]
53
-
54
- circulation_ratio = sum(stock_gdfx_free_top_10['circulation_ratio'])
55
- mv_circulation_ratio = round((100 - circulation_ratio) / 100, 2)
56
- # 防止错误数据
57
- if mv_circulation_ratio < 0:
58
- mv_circulation_ratio = 1
59
- return mv_circulation_ratio
60
-
61
-
62
- def get_east_money_stock_info():
63
- all_real_time_quotes = east_money_stock_v2_api.get_all_real_time_quotes()
64
- all_real_time_quotes = all_real_time_quotes[['symbol',
65
- 'name',
66
- "now_price",
67
- 'total_mv',
68
- 'flow_mv',
69
- 'pe_ttm',
70
- 'sz_sh',
71
- 'area',
72
- 'pb',
73
- 'list_date',
74
- 'ROE',
75
- 'total_share',
76
- 'flow_share',
77
- 'industry',
78
- 'amount',
79
- "hk_stock_code",
80
- "hk_stock_name",
81
- 'concept']]
82
-
83
- return all_real_time_quotes
84
-
85
-
86
- def create_index():
87
- mongodb_util.create_index('company_info',
88
- [("classification", 1)])
89
- mongodb_util.create_index('company_info',
90
- [("industry", 1)])
91
- mongodb_util.create_index('company_info',
92
- [("flow_mv", 1)])
93
- mongodb_util.create_index('company_info',
94
- [("list_date", 1)])
95
- mongodb_util.create_index('company_info',
96
- [("symbol", 1)])
97
-
98
-
99
- # 同步公司基本信息
100
-
101
- def sync_company_base_info(symbol_list):
102
- global result
103
- result = []
104
- create_index()
105
- east_money_stock_info = get_east_money_stock_info()
106
- de_listed_stock_list = company_common_service_api.get_de_list_company()
107
- east_money_stock_info = east_money_stock_info.loc[~(
108
- east_money_stock_info['symbol'].isin(de_listed_stock_list))]
109
- east_money_stock_info = common_service_fun_api.exclude_ts_symbol(east_money_stock_info)
110
- east_money_stock_info = east_money_stock_info.loc[~((east_money_stock_info['industry'] == '-')
111
- & (east_money_stock_info['now_price'] == 0))]
112
-
113
- east_money_stock_info = common_service_fun_api.total_mv_classification(east_money_stock_info)
114
- east_money_stock_info = common_service_fun_api.classify_symbol(east_money_stock_info)
115
-
116
- # 将日期数值转换为日期时间格式
117
- east_money_stock_info['list_date_01'] = pd.to_datetime(east_money_stock_info['list_date'], format='%Y%m%d')
118
-
119
- # 开盘啦实时数据
120
- kpl_real_time_quotes = kpl_real_time_quotes_api.get_kpl_real_time_quotes()
121
-
122
- if symbol_list is not None:
123
- east_money_stock_info = east_money_stock_info.loc[east_money_stock_info['symbol'].isin(symbol_list)]
124
- count = east_money_stock_info.shape[0]
125
- page_number = round(count / MAX_PAGE_NUMBER, 0) + 1
126
- page_number = int(page_number)
127
- threads = []
128
-
129
- exist_company_df = mongodb_util.find_all_data(db_name_constant.COMPANY_INFO)
130
-
131
- # 创建多个线程来获取数据
132
- for page in range(page_number): # 0到100页
133
- end_count = (page + 1) * MAX_PAGE_NUMBER
134
- begin_count = page * MAX_PAGE_NUMBER
135
- page_df = east_money_stock_info.iloc[begin_count:end_count]
136
- thread = threading.Thread(target=single_thread_sync_company_info,
137
- args=(page_df, kpl_real_time_quotes, exist_company_df))
138
- threads.append(thread)
139
- thread.start()
140
-
141
- # 等待所有线程完成
142
- for thread in threads:
143
- thread.join()
144
-
145
- fail_df = east_money_stock_info.loc[east_money_stock_info['symbol'].isin(result)]
146
- single_thread_sync_company_info(fail_df, kpl_real_time_quotes, exist_company_df)
147
-
148
-
149
- def single_thread_sync_company_info(east_money_stock_info,
150
- kpl_real_time_quotes, exist_company_df):
151
- global result
152
- fail_list = []
153
- for company_one in east_money_stock_info.itertuples():
154
- try:
155
- # 同步公司控股子公司信息 异步执行
156
- sync_company_hold_info_api.sync_company_hold_info(company_one.symbol)
157
-
158
- company_info_type = ths_company_info_web.get_company_info_detail(company_one.symbol)
159
- company_info_type = set_kzz_debt(company_info_type, company_one.symbol)
160
- company_info_type['first_industry_code'] = company_info_type['hycode'].apply(
161
- lambda x: x[1:3] + '0000')
162
- company_info_type['second_industry_code'] = company_info_type['hy2code'].apply(
163
- lambda x: x[1:5] + '00')
164
- company_info_type['third_industry_code'] = company_info_type['hy3code'].apply(
165
- lambda x: x[1:7])
166
-
167
- company_info_type['first_sw_industry'] = company_info_type['hy']
168
- company_info_type['second_sw_industry'] = company_info_type['hy2']
169
- company_info_type['third_sw_industry'] = company_info_type['hy3']
170
- # 保存申万行业信息
171
- save_sw_data(company_info_type)
172
-
173
- company_info_type['_id'] = company_one.symbol
174
-
175
- company_info_type['name'] = company_one.name
176
-
177
- company_info_type['em_industry'] = company_one.industry
178
- company_info_type['em_concept'] = company_one.concept
179
-
180
- company_info_type['hk_stock_code'] = company_one.hk_stock_code
181
- company_info_type['hk_stock_name'] = company_one.hk_stock_name
182
-
183
- company_info_type['now_price'] = company_one.now_price
184
- company_info_type['total_share'] = company_one.total_share
185
- company_info_type['flow_share'] = company_one.flow_share
186
- company_info_type['total_mv'] = company_one.total_mv
187
- company_info_type['flow_mv'] = company_one.flow_mv
188
- company_info_type['area'] = company_one.area
189
- company_info_type['list_date'] = company_one.list_date
190
- now_date = datetime.now()
191
- # 计算日期差值 距离现在上市时间
192
- company_info_type['diff_days'] = (now_date - company_one.list_date_01).days
193
-
194
- company_info_type['pe_ttm'] = company_one.pe_ttm
195
- company_info_type['pb'] = company_one.pb
196
- company_info_type['ROE'] = company_one.ROE
197
- company_info_type['flow_mv_sp'] = company_one.flow_mv_sp
198
- company_info_type['total_mv_sp'] = company_one.total_mv_sp
199
- company_info_type['flow_mv_level'] = company_one.flow_mv_level
200
- company_info_type['classification'] = company_one.classification
201
- company_info_type['mv_circulation_ratio'] = calculate_circulation_ratio(company_one.symbol)
202
- # 获取同花顺最新概念
203
- company_info_type = ths_concept_common_service_api.set_ths_concept(company_one.symbol, company_info_type)
204
- now_date = datetime.now()
205
- str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
206
- company_info_type['sync_date'] = str_now_date
207
- fix_symbol_industry_df = company_constant_data.get_fix_symbol_industry()
208
- if company_one.symbol in list(fix_symbol_industry_df['symbol']):
209
- # fix sw_industry
210
- company_info_type = company_constant_data.fix_symbol_industry(company_info_type, company_one.symbol)
211
-
212
- # todo fix industry
213
- company_info_type['industry'] = company_info_type['second_sw_industry']
214
- company_info_type['amount'] = company_one.amount
215
-
216
- company_info_type['kpl_plate_list_info'] = '-'
217
- company_info_type['kpl_plate_name'] = '-'
218
- company_info_type['kpl_most_relative_name'] = '-'
219
- now_date = datetime.now()
220
- str_day = now_date.strftime('%Y-%m-%d')
221
- deal_days = k_line_common_service_api.get_deal_days(str_day, company_one.symbol)
222
- company_info_type['deal_days'] = deal_days
223
-
224
- # 设置年报信息
225
- company_info_type = get_recent_year_income(company_one.symbol, company_info_type, exist_company_df)
226
-
227
- try:
228
- if data_frame_util.is_not_empty(kpl_real_time_quotes):
229
- kpl_real_time_quotes_one = kpl_real_time_quotes.loc[
230
- kpl_real_time_quotes['symbol'] == company_one.symbol]
231
-
232
- if data_frame_util.is_not_empty(kpl_real_time_quotes_one):
233
- company_info_type['kpl_plate_name'] = list(kpl_real_time_quotes_one['plate_name_list'])[0]
234
- company_info_type['kpl_most_relative_name'] = \
235
- list(kpl_real_time_quotes_one['most_relative_name'])[
236
- 0]
237
- company_info_type = set_kpl_data(kpl_real_time_quotes_one, company_info_type, company_one)
238
-
239
- if bool(1 - ("kpl_plate_name" in company_info_type.columns)) or bool(
240
- 1 - ("kpl_most_relative_name" in company_info_type.columns)):
241
- company_info_type['kpl_plate_name'] = ""
242
- company_info_type['kpl_most_relative_name'] = ""
243
- except BaseException as e:
244
- logger.warning("设置开盘啦数据异常:{},{}", company_one.symbol, e)
245
-
246
- company_info_type = company_constant_data.filed_sort(company_info_type)
247
- mongodb_util.save_mongo(company_info_type.copy(), 'company_info_base')
248
- logger.info("同步公司信息完成:{}", company_one.symbol + '-' + company_one.name)
249
- except BaseException as e:
250
- fail_list.append(company_one.symbol)
251
- logger.error("同步公司信息发生异常:{},{}", company_one.symbol, e)
252
- with result_lock:
253
- # 使用锁来保护 result 变量的访问,将每页的数据添加到结果中
254
- result = fail_list
255
-
256
-
257
- def set_kpl_data(kpl_real_time_quotes_one, company_info_type, company_one):
258
- if data_frame_util.is_not_empty(kpl_real_time_quotes_one):
259
- company_info_type['kpl_plate_name'] = list(kpl_real_time_quotes_one['plate_name_list'])[0]
260
- company_info_type['kpl_most_relative_name'] = list(kpl_real_time_quotes_one['most_relative_name'])[
261
- 0]
262
- symbol = company_one.symbol
263
-
264
- query = {'symbol': symbol, "index_class": kpl_constant.FIRST_INDEX}
265
- kpl_best_choose_index_detail = mongodb_util.find_query_data('kpl_best_choose_index_detail', query)
266
- if data_frame_util.is_not_empty(kpl_best_choose_index_detail):
267
- kpl_best_choose_index_detail = kpl_best_choose_index_detail[[
268
- "plate_code",
269
- "plate_name",
270
- "first_plate_code",
271
- "first_plate_name",
272
- "index_class"
273
- ]]
274
-
275
- # 去除空格
276
- kpl_best_choose_index_detail['plate_name'] = kpl_best_choose_index_detail['plate_name'].str.replace(' ', '')
277
- # 去除空格
278
- kpl_best_choose_index_detail['first_plate_name'] = kpl_best_choose_index_detail[
279
- 'first_plate_name'].str.replace(' ', '')
280
-
281
- company_info_type.loc[:, 'kpl_plate_list_info'] = kpl_best_choose_index_detail.to_string(index=False)
282
- return company_info_type
283
-
284
-
285
- # 获取可转债信息
286
- @lru_cache(maxsize=None)
287
- def get_kzz_debt_info():
288
- query = {}
289
- kzz_debt_info_df = mongodb_util.find_query_data(db_name_constant.KZZ_DEBT_INFO, query)
290
- kzz_debt_info_df = kzz_debt_info_df[[
291
- 'symbol',
292
- 'name',
293
- 'stock_code',
294
- 'apply_date',
295
- 'list_date',
296
- 'due_date'
297
- ]]
298
- return kzz_debt_info_df
299
-
300
-
301
- def set_kzz_debt(df, symbol):
302
- kzz_debt_info_df_all = get_kzz_debt_info()
303
- kzz_debt_info_df = kzz_debt_info_df_all.loc[kzz_debt_info_df_all['stock_code'] == symbol]
304
- df.loc[:, 'kzz_debt_list'] = ''
305
- if data_frame_util.is_not_empty(kzz_debt_info_df):
306
- kzz_debt_info_df_list = kzz_debt_info_df.to_dict(orient='records')
307
- df.at[0, 'kzz_debt_list'] = kzz_debt_info_df_list
308
- return df
309
-
310
-
311
- # 保存申万行业分类
312
- def save_sw_data(company_info_type):
313
- now_date = datetime.now()
314
- hour = now_date.hour
315
- if hour <= 15:
316
- return company_info_type
317
- first_sw_info = company_info_type[[
318
- 'first_sw_industry',
319
- 'first_industry_code'
320
- ]].copy()
321
-
322
- first_sw_info.loc[:, "industry_code"] = first_sw_info['first_industry_code']
323
- first_sw_info.loc[:, "_id"] = first_sw_info['first_industry_code']
324
- first_sw_info.loc[:, "second_sw_industry"] = 0
325
- first_sw_info.loc[:, "third_sw_industry"] = 0
326
- first_sw_info.loc[:, "second_industry_code"] = 0
327
- first_sw_info.loc[:, "third_industry_code"] = 0
328
- first_sw_info = first_sw_info[[
329
- "_id",
330
- "industry_code",
331
- 'first_industry_code',
332
- 'first_sw_industry',
333
- 'second_industry_code',
334
- 'second_sw_industry',
335
- 'third_industry_code',
336
- 'third_sw_industry'
337
- ]]
338
- mongodb_util.save_mongo(first_sw_info, 'sw_industry')
339
-
340
- second_sw_info = company_info_type[[
341
- 'first_industry_code',
342
- 'first_sw_industry',
343
- 'second_sw_industry',
344
- 'second_industry_code',
345
- ]].copy()
346
-
347
- second_sw_info.loc[:, "industry_code"] = second_sw_info['second_industry_code']
348
- second_sw_info.loc[:, "_id"] = second_sw_info['industry_code']
349
-
350
- second_sw_info.loc[:, "third_sw_industry"] = 0
351
- second_sw_info.loc[:, "third_sw_industry"] = 0
352
- second_sw_info.loc[:, "third_industry_code"] = 0
353
- second_sw_info = second_sw_info[[
354
- "_id",
355
- "industry_code",
356
- 'first_industry_code',
357
- 'first_sw_industry',
358
- 'second_industry_code',
359
- 'second_sw_industry',
360
- 'third_industry_code',
361
- 'third_sw_industry'
362
- ]]
363
- mongodb_util.save_mongo(second_sw_info, 'sw_industry')
364
-
365
- third_sw_info = company_info_type[[
366
- 'first_industry_code',
367
- 'first_sw_industry',
368
- 'second_industry_code',
369
- 'second_sw_industry',
370
- 'third_industry_code',
371
- 'third_sw_industry'
372
- ]].copy()
373
-
374
- third_sw_info.loc[:, "industry_code"] = third_sw_info['third_industry_code']
375
-
376
- third_sw_info.loc[:, "_id"] = third_sw_info['industry_code']
377
-
378
- third_sw_info = third_sw_info[[
379
- "_id",
380
- "industry_code",
381
- 'first_industry_code',
382
- 'first_sw_industry',
383
- 'second_industry_code',
384
- 'second_sw_industry',
385
- 'third_industry_code',
386
- 'third_sw_industry'
387
- ]]
388
- mongodb_util.save_mongo(third_sw_info, 'sw_industry')
389
-
390
-
391
- # 获取最近年报收入
392
- def get_recent_year_income(symbol, company_info_type, exist_company_df):
393
- now_date = datetime.now()
394
- hour = now_date.hour
395
- if hour <= 15:
396
- exist_company_one_df = exist_company_df.loc[exist_company_df['_id'] == symbol]
397
- if data_frame_util.is_not_empty(exist_company_one_df):
398
- company_info_type['operate_profit'] = list(exist_company_one_df['operate_profit'])[0]
399
- company_info_type['total_operate_income'] = list(exist_company_one_df['total_operate_income'])[0]
400
- else:
401
- company_info_type['operate_profit'] = 0
402
- company_info_type['total_operate_income'] = 0
403
- return company_info_type
404
- query = {'symbol': symbol, "REPORT_TYPE": "年报"}
405
- em_stock_profit = mongodb_util.descend_query(query, db_name_constant.EM_STOCK_PROFIT, 'REPORT_DATE', 1)
406
- if data_frame_util.is_not_empty(em_stock_profit):
407
- company_info_type['operate_profit'] = list(em_stock_profit['OPERATE_PROFIT'])[0]
408
- total_operate_income = list(em_stock_profit['TOTAL_OPERATE_INCOME'])[0]
409
- # 金融机构大多收入计入在这个字段中
410
- if total_operate_income == 0:
411
- total_operate_income = list(em_stock_profit['OPERATE_INCOME'])[0]
412
-
413
- company_info_type['total_operate_income'] = total_operate_income
414
- else:
415
- company_info_type['operate_profit'] = 0
416
- company_info_type['total_operate_income'] = 0
417
- company_info_type['operate_profit'] = round(
418
- company_info_type['operate_profit'] / common_service_fun_api.HUNDRED_MILLION, 2)
419
- company_info_type['total_operate_income'] = round(
420
- company_info_type['total_operate_income'] / common_service_fun_api.HUNDRED_MILLION, 2)
421
- return company_info_type
422
-
423
-
424
- import mns_scheduler.company_info.constant.company_constant_data as company_constant_data
425
-
426
- if __name__ == '__main__':
427
- # sync_company_base_info()
428
- # fix_company_industry()
429
- # calculate_circu_ratio("601069")
430
- # sync_company_base_info()
431
- # 300293
432
- # sync_company_base_info(None)
433
- # new_company_info_update()
434
- # query = {"total_operate_income": 0}
435
- # un_report_company_info = mongodb_util.find_query_data(db_name_constant.COMPANY_INFO, query)
436
- # symbol_list = list(un_report_company_info['symbol'])
437
- fix_symbol_industry_df = company_constant_data.get_fix_symbol_industry()
438
- sync_company_base_info(list(fix_symbol_industry_df['symbol']))
439
- # group_by_industry()
@@ -1,40 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
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
- query = {'symbol': symbol}
31
- result = mongodb_util.remove_data(query, db_name_constant.COMPANY_HOLDING_INFO)
32
- if result.acknowledged:
33
- company_hold_info_df['sync_str_date'] = sync_str_date
34
- mongodb_util.insert_mongo(company_hold_info_df, db_name_constant.COMPANY_HOLDING_INFO)
35
- except BaseException as e:
36
- logger.error("同步公司控股子公司信息:{},{}", symbol, e)
37
-
38
-
39
- if __name__ == '__main__':
40
- 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') + 16
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.api.em.east_money_stock_v2_api as east_money_stock_v2_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 = east_money_stock_v2_api.get_all_real_time_quotes()
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()
@@ -1,84 +0,0 @@
1
- import os
2
- import sys
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.constant.db_name_constant as db_name_constant
9
- import mns_common.component.common_service_fun_api as common_service_fun_api
10
- import mns_common.component.cache.cache_service as cache_service
11
- import mns_common.utils.cmd_util as cmd_util
12
- import mns_common.utils.data_frame_util as data_frame_util
13
- from loguru import logger
14
- from datetime import datetime
15
- import mns_common.utils.date_handle_util as date_handle_util
16
- from mns_common.db.MongodbUtil import MongodbUtil
17
-
18
- mongodb_util = MongodbUtil('27017')
19
-
20
- MAX_NUMBER_KEY = 'max_number_key'
21
- # 实时行情同步任务 python名称
22
- REAL_TIME_SCHEDULER_NAME = "sync_realtime_quotes_task"
23
- # 实时行情补偿任务 python名称
24
- REAL_TIME_TASK_NAME = "realtime_quotes_now_sync"
25
-
26
- REAL_TIME_SCHEDULER_NAME_PATH = 'H:\\real_time_task.bat'
27
-
28
-
29
- def get_real_time_max_number():
30
- number = common_service_fun_api.realtime_quotes_now_max_number(db_name_constant.REAL_TIME_QUOTES_NOW,
31
- 'number')
32
-
33
- return number
34
-
35
-
36
- # 检查数据同步最大值
37
- def check_max_number():
38
- now_max_number = get_real_time_max_number()
39
- last_minute_number = cache_service.get_cache(MAX_NUMBER_KEY)
40
- cache_service.set_cache(MAX_NUMBER_KEY, now_max_number)
41
- if last_minute_number is None:
42
- return True
43
- elif now_max_number == last_minute_number:
44
- return False
45
- else:
46
- return True
47
-
48
-
49
- # 实时行情数据同步状态check
50
- def run_check_real_time_data_sync_status():
51
- now_date = datetime.now()
52
- if bool(1 - date_handle_util.is_trade_time(now_date)):
53
- return False
54
- flag = check_max_number()
55
- if bool(1 - flag):
56
- all_cmd_processes = cmd_util.get_all_process()
57
- if data_frame_util.is_empty(all_cmd_processes):
58
- return None
59
- all_cmd_processes_real_time_task = get_real_time_quotes_task(all_cmd_processes)
60
- if data_frame_util.is_empty(all_cmd_processes_real_time_task):
61
- return None
62
- for match_task_one in all_cmd_processes_real_time_task.itertuples():
63
- try:
64
- processes_pid = match_task_one.process_pid
65
- # 关闭当前进程
66
- cmd_util.kill_process_by_pid(processes_pid)
67
- # 清空临时数据表
68
- mongodb_util.remove_all_data(db_name_constant.REAL_TIME_QUOTES_NOW)
69
-
70
- except BaseException as e:
71
- logger.error("关闭实时行情任务异常:{}", e)
72
- # 重开任务进程
73
- cmd_util.open_bat_file(REAL_TIME_SCHEDULER_NAME_PATH)
74
-
75
-
76
- def get_real_time_quotes_task(all_cmd_processes):
77
- return all_cmd_processes[
78
- (all_cmd_processes['total_info'].str.contains(REAL_TIME_SCHEDULER_NAME, case=False, na=False))
79
- | (all_cmd_processes['total_info'].str.contains(REAL_TIME_TASK_NAME, case=False, na=False))]
80
-
81
-
82
- if __name__ == '__main__':
83
- while True:
84
- run_check_real_time_data_sync_status()
@@ -1,33 +0,0 @@
1
- import sys
2
- import os
3
-
4
- file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
6
- project_path = file_path[0:end]
7
- sys.path.append(project_path)
8
- import mns_common.api.em.east_money_debt_api as east_money_debt_api
9
- from datetime import datetime
10
- import mns_common.constant.db_name_constant as db_name_constant
11
- from mns_common.db.MongodbUtil import MongodbUtil
12
-
13
- mongodb_util = MongodbUtil('27017')
14
-
15
-
16
- # 同步可转债信息
17
- def sync_debt_info():
18
- now_date = datetime.now()
19
- str_now_day = now_date.strftime('%Y-%m-%d')
20
- kzz_bond_info_df = east_money_debt_api.get_kzz_bond_info()
21
- kzz_bond_info_df = kzz_bond_info_df.fillna(0)
22
- kzz_bond_info_df['apply_date'] = kzz_bond_info_df['apply_date'].astype(str)
23
- kzz_bond_info_df['winning_date'] = kzz_bond_info_df['winning_date'].astype(str)
24
- kzz_bond_info_df['list_date'] = kzz_bond_info_df['list_date'].astype(str)
25
- kzz_bond_info_df['due_date'] = kzz_bond_info_df['due_date'].astype(str)
26
- kzz_bond_info_df = kzz_bond_info_df.loc[kzz_bond_info_df['due_date'] >= str_now_day]
27
- mongodb_util.remove_all_data(db_name_constant.KZZ_DEBT_INFO)
28
- kzz_bond_info_df['_id'] = kzz_bond_info_df['symbol']
29
- mongodb_util.insert_mongo(kzz_bond_info_df, db_name_constant.KZZ_DEBT_INFO)
30
-
31
-
32
- if __name__ == '__main__':
33
- sync_debt_info()