mns-scheduler 1.0.8.7__py3-none-any.whl → 1.4.3.2__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 (156) hide show
  1. mns_scheduler/__init__.py +1 -3
  2. mns_scheduler/company_info/announce/company_announce_sync_service.py +65 -0
  3. mns_scheduler/company_info/{company_info_sync_api.py → base/sync_company_base_info_api.py} +239 -227
  4. mns_scheduler/company_info/base/sync_company_hold_info_api.py +37 -0
  5. mns_scheduler/company_info/base/sync_company_product_area_industry.py +161 -0
  6. mns_scheduler/company_info/clean/company_info_clean_api.py +133 -0
  7. mns_scheduler/company_info/constant/company_constant_data.py +497 -0
  8. mns_scheduler/company_info/{de_list_stock_service.py → de_list_stock/de_list_stock_service.py} +1 -1
  9. mns_scheduler/company_info/em_stock_info/__init__.py +7 -0
  10. mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +80 -0
  11. mns_scheduler/company_info/remark/__init__.py +7 -0
  12. mns_scheduler/company_info/remark/company_remark_info_sync.py +46 -0
  13. mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
  14. mns_scheduler/concept/clean/ths_concept_clean_api.py +74 -51
  15. mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +112 -56
  16. mns_scheduler/concept/ths/common/ths_concept_update_common_api.py +6 -6
  17. mns_scheduler/concept/ths/detaill/__init__.py +0 -0
  18. mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +226 -0
  19. mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_new_index_api.py +169 -0
  20. mns_scheduler/concept/ths/update_concept_info/sync_one_concept_all_symbols_api.py +11 -23
  21. mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +19 -15
  22. mns_scheduler/db/col_move_service.py +10 -7
  23. mns_scheduler/db/db_status.py +1 -1
  24. mns_scheduler/db/script/__init__.py +7 -0
  25. mns_scheduler/db/script/col_move_script.py +45 -0
  26. mns_scheduler/db/script/db_move/__init__.py +7 -0
  27. mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
  28. mns_scheduler/db/script/sync/__init__.py +7 -0
  29. mns_scheduler/db/script/sync/local_mongo_util.py +231 -0
  30. mns_scheduler/db/script/sync/remote_data_sync_to_local.py +105 -0
  31. mns_scheduler/db/script/sync/remote_mongo_util.py +306 -0
  32. mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +80 -0
  33. mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
  34. mns_scheduler/db/script/update/__init__.py +7 -0
  35. mns_scheduler/db/script/update/update_col_field.py +36 -0
  36. mns_scheduler/finance/__init__.py +1 -1
  37. mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +3 -3
  38. mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +30 -25
  39. mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +4 -4
  40. mns_scheduler/finance/sync_financial_report_service_task.py +202 -0
  41. mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
  42. mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
  43. mns_scheduler/hk/__init__.py +1 -1
  44. mns_scheduler/hk/hk_company_info_sync_service_api.py +49 -5
  45. mns_scheduler/hk/hk_industry_info_sync_service_api.py +68 -0
  46. mns_scheduler/industry/__init__.py +7 -0
  47. mns_scheduler/industry/ths/__init__.py +7 -0
  48. mns_scheduler/industry/ths/ths_industry_index_service.py +58 -0
  49. mns_scheduler/industry/ths/ths_industry_sync_service.py +68 -0
  50. mns_scheduler/irm/__init__.py +1 -1
  51. mns_scheduler/irm/api/__init__.py +1 -1
  52. mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +1 -1
  53. mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +1 -1
  54. mns_scheduler/irm/stock_irm_cninfo_service.py +15 -13
  55. mns_scheduler/k_line/clean/daily/__init__.py +1 -1
  56. mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +57 -7
  57. mns_scheduler/k_line/clean/daily/daily_k_line_service.py +16 -3
  58. mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
  59. mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -31
  60. mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
  61. mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +125 -27
  62. mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +72 -17
  63. mns_scheduler/k_line/common/__init__.py +7 -0
  64. mns_scheduler/k_line/common/k_line_common_api.py +188 -0
  65. mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
  66. mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
  67. mns_scheduler/k_line/month_week_daily/bfq_k_line_sync.py +77 -0
  68. mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +14 -14
  69. mns_scheduler/k_line/sync_status/__init__.py +7 -0
  70. mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
  71. mns_scheduler/k_line/test/__init__.py +7 -0
  72. mns_scheduler/k_line/test/k_line_info_clean_his_data.py +41 -0
  73. mns_scheduler/k_line/year_quarter/__init__.py +7 -0
  74. mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
  75. mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +4 -2
  76. mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
  77. mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +12 -7
  78. mns_scheduler/lhb/__init__.py +1 -1
  79. mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
  80. mns_scheduler/open/__init__.py +1 -1
  81. mns_scheduler/open/sync_one_day_open_data_to_db_service.py +6 -22
  82. mns_scheduler/risk/__init__.py +1 -1
  83. mns_scheduler/risk/compliance/__init__.py +0 -0
  84. mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +71 -0
  85. mns_scheduler/risk/financial/__init__.py +0 -0
  86. mns_scheduler/risk/financial/annual_report_audit_check_api.py +54 -0
  87. mns_scheduler/risk/financial/net_assets_check_api.py +75 -0
  88. mns_scheduler/risk/financial/profit_income_check_api.py +80 -0
  89. mns_scheduler/risk/financial/stock_equity_mortgage_check_api.py +1 -0
  90. mns_scheduler/risk/financial_report_risk_check_api.py +42 -0
  91. mns_scheduler/risk/major_violations/__init__.py +0 -0
  92. mns_scheduler/risk/{register_and_investigate_stock_sync_api.py → major_violations/register_and_investigate_stock_sync_api.py} +17 -8
  93. mns_scheduler/risk/self/__init__.py +0 -0
  94. mns_scheduler/risk/{wei_pan_stock_api.py → self/wei_pan_stock_api.py} +10 -4
  95. mns_scheduler/risk/test/__init__.py +7 -0
  96. mns_scheduler/{finance → risk}/test/fix_blask_list.py +6 -10
  97. mns_scheduler/risk/transactions/__init__.py +0 -0
  98. mns_scheduler/risk/transactions/transactions_check_api.py +183 -0
  99. mns_scheduler/self_choose/__init__.py +7 -0
  100. mns_scheduler/self_choose/ths_self_choose_service.py +158 -0
  101. mns_scheduler/trade/auto_ipo_buy_api.py +2 -2
  102. mns_scheduler/trade/auto_login/__init__.py +7 -0
  103. mns_scheduler/trade/auto_login/trader_auto_service.py +32 -0
  104. mns_scheduler/trade/auto_sell_service_api.py +10 -8
  105. mns_scheduler/trade/balance/__init__.py +7 -0
  106. mns_scheduler/trade/balance/ths_account_balance_service.py +7 -0
  107. mns_scheduler/trade/sync_position_api.py +41 -8
  108. mns_scheduler/trade/task/__init__.py +7 -0
  109. mns_scheduler/trade/task/trader_task_service.py +65 -0
  110. mns_scheduler/trade/tfp/__init__.py +7 -0
  111. mns_scheduler/trade/tfp/stock_tfp_info_sync.py +56 -0
  112. mns_scheduler/zb/stock_zb_pool_sync.py +1 -15
  113. mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -3
  114. mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +12 -8
  115. mns_scheduler/zt/open_data/kcx_high_chg_open_data_sync.py +10 -25
  116. mns_scheduler/zt/script/__init__.py +1 -1
  117. mns_scheduler/zt/script/fix_error_deal_day.py +41 -0
  118. mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -11
  119. mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
  120. mns_scheduler/zt/script/sync_now_higt_chg_zt.py +43 -0
  121. mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +413 -0
  122. mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +193 -0
  123. mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +58 -0
  124. mns_scheduler/zz_task/compensation/__init__.py +0 -0
  125. mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
  126. mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
  127. mns_scheduler/zz_task/data_sync_task.py +271 -121
  128. {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/METADATA +1 -1
  129. mns_scheduler-1.4.3.2.dist-info/RECORD +169 -0
  130. {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/WHEEL +1 -1
  131. mns_scheduler/backup/app/ths_new_concept_sync_app.py +0 -122
  132. mns_scheduler/backup/em/em_new_concept_his_sync.py +0 -99
  133. mns_scheduler/backup/em/em_new_concept_sync_common_api.py +0 -139
  134. mns_scheduler/backup/em/em_new_concept_sync_web.py +0 -55
  135. mns_scheduler/backup/wen_cai/wen_cai_concept_sync.py +0 -51
  136. mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
  137. mns_scheduler/company_info/company_constant_data.py +0 -322
  138. mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_by_ak_api.py +0 -103
  139. mns_scheduler/concept/ths/sync_new_index/sync_ths_new_concept_by_web_api.py +0 -89
  140. mns_scheduler/finance/financial_high_risk_stock_clean_service_api.py +0 -202
  141. mns_scheduler/finance/sync_financial_report_service_api.py +0 -113
  142. mns_scheduler/real_time/realtime_quotes_now_create_db_index.py +0 -27
  143. mns_scheduler/real_time/realtime_quotes_now_sync.py +0 -232
  144. mns_scheduler/risk/stock_equity_mortgage_sync_api.py +0 -32
  145. mns_scheduler/zt/zt_pool/zt_pool_sync_api.py +0 -151
  146. mns_scheduler/zz_task/sync_realtime_quotes_task.py +0 -28
  147. mns_scheduler-1.0.8.7.dist-info/RECORD +0 -112
  148. /mns_scheduler/{backup/app → company_info/announce}/__init__.py +0 -0
  149. /mns_scheduler/{backup/em → company_info/base}/__init__.py +0 -0
  150. /mns_scheduler/{backup/wen_cai → company_info/clean}/__init__.py +0 -0
  151. /mns_scheduler/{big_deal → company_info/constant}/__init__.py +0 -0
  152. /mns_scheduler/{real_time → company_info/de_list_stock}/__init__.py +0 -0
  153. /mns_scheduler/{backup → finance/em}/__init__.py +0 -0
  154. /mns_scheduler/finance/{test → xue_qiu}/__init__.py +0 -0
  155. /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
  156. {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,161 @@
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
+
9
+ from mns_common.db.MongodbUtil import MongodbUtil
10
+ import mns_common.constant.extra_income_db_name as extra_income_db_name
11
+ import mns_scheduler.finance.xue_qiu.down_load_xueqiu_report_api as down_load_xueqiu_report_api
12
+ import mns_common.component.common_service_fun_api as common_service_fun_api
13
+ import pandas as pd
14
+ from loguru import logger
15
+ import time
16
+ import mns_common.utils.data_frame_util as data_frame_util
17
+ import mns_common.component.cookie.cookie_info_service as cookie_info_service
18
+ from datetime import datetime
19
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
20
+
21
+ mongodb_util_27017 = MongodbUtil('27017')
22
+
23
+
24
+ # report_type income 利润表
25
+ # cash_flow 现金流量
26
+ # balance 资产负债
27
+ # 同步所有股票 报表
28
+ def sync_all_stocks_report():
29
+ em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
30
+ em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
31
+ # 或等效写法 df['A'].str[0:6]
32
+
33
+ fail_list = []
34
+
35
+ xue_qiu_cookie = cookie_info_service.get_xue_qiu_cookie()
36
+ report_type_list = ['income', 'balance', 'cash_flow']
37
+ for stock_one in em_a_stock_info_df.itertuples():
38
+ fail_list = save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, True, fail_list, '', False)
39
+
40
+ handle_number = 0
41
+ # 处理失败的
42
+ while len(fail_list) > 0:
43
+ fail_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'].isin(fail_list)]
44
+ for fail_one in fail_df.itertuples():
45
+ fail_list = save_one_symbol_data(fail_one, report_type_list, xue_qiu_cookie, True, fail_list, '', False)
46
+ handle_number = handle_number + 1
47
+ if handle_number > 10:
48
+ break
49
+
50
+
51
+ def save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, save_tag, fail_list, report_name, check_exist):
52
+ try:
53
+ symbol_prefix = stock_one.symbol_prefix
54
+ name = stock_one.name
55
+ symbol = stock_one.symbol
56
+ for report_type in report_type_list:
57
+ if report_type == 'income':
58
+ col_name = extra_income_db_name.XUE_QIU_LRB_INCOME
59
+ elif report_type == 'balance':
60
+ col_name = extra_income_db_name.XUE_QIU_ASSET_DEBT
61
+ elif report_type == 'cash_flow':
62
+ col_name = extra_income_db_name.XUE_QIU_CASH_FLOW
63
+ if check_exist:
64
+ query_exist = {'symbol': symbol, 'report_name': report_name}
65
+ # 存在数据 不在同步
66
+ if mongodb_util_27017.exist_data_query(col_name, query_exist):
67
+ continue
68
+
69
+ index_create = [('symbol', 1), ('report_date', 1)]
70
+ mongodb_util_27017.create_index(col_name, index_create)
71
+
72
+ index_create_01 = [('symbol', 1), ('sync_time', 1)]
73
+ mongodb_util_27017.create_index(col_name, index_create_01)
74
+
75
+ if check_exist:
76
+ # 季度同步只同步一条数据
77
+ result_df = down_load_xueqiu_report_api.get_xue_qiu_report(symbol_prefix, report_type, xue_qiu_cookie,
78
+ 1,
79
+ 'all')
80
+ else:
81
+ result_df = down_load_xueqiu_report_api.get_xue_qiu_report(symbol_prefix, report_type, xue_qiu_cookie,
82
+ 200,
83
+ 'all')
84
+
85
+ now_date = datetime.now()
86
+ sync_time = now_date.strftime('%Y-%m-%d %H:%M:%S')
87
+
88
+ if data_frame_util.is_empty(result_df):
89
+ logger.error("财务信息为空,代码:{}:{}", symbol, name)
90
+ continue
91
+ else:
92
+ # 季度同步check
93
+ if check_exist:
94
+ result_df = result_df.loc[result_df['report_name'] == report_name]
95
+ if data_frame_util.is_empty(result_df):
96
+ continue
97
+
98
+ result_df['sync_time'] = sync_time
99
+ time.sleep(0.5)
100
+ # 1. 将毫秒时间戳转为 datetime
101
+ result_df['report_date'] = pd.to_datetime(result_df['report_date'], unit='ms')
102
+
103
+ # 2. 格式化为 '%Y-%m-%d' 字符串
104
+ result_df['report_date'] = result_df['report_date'].dt.strftime('%Y-%m-%d')
105
+
106
+ result_df['_id'] = symbol + '_' + result_df['report_date']
107
+ result_df['symbol'] = symbol
108
+
109
+ # 1. 将毫秒时间戳转为 datetime
110
+ result_df['ctime'] = pd.to_datetime(result_df['ctime'], unit='ms')
111
+
112
+ # 2. 格式化为 '%Y-%m-%d' 字符串
113
+ result_df['ctime'] = result_df['ctime'].dt.strftime('%Y-%m-%d')
114
+ result_df.loc[result_df['report_name'].str.contains('年报'), 'period'] = 4
115
+ result_df.loc[result_df['report_name'].str.contains('一季报'), 'period'] = 1
116
+ result_df.loc[result_df['report_name'].str.contains('中报'), 'period'] = 2
117
+ result_df.loc[result_df['report_name'].str.contains('三季报'), 'period'] = 3
118
+ result_df['year'] = result_df['report_name'].str[:4]
119
+ if save_tag:
120
+ mongodb_util_27017.save_mongo(result_df, col_name)
121
+ else:
122
+ mongodb_util_27017.insert_mongo(result_df, col_name)
123
+
124
+ if symbol in fail_list:
125
+ fail_list.remove(symbol)
126
+ logger.info("同步财务数据完成:{}:{}", symbol, name, report_name)
127
+ except BaseException as e:
128
+ logger.error("同步错误:{},异常信息:{}", symbol, e)
129
+ fail_list.append(symbol)
130
+ return fail_list
131
+
132
+
133
+ def sync_xue_qiu_very_period_report(report_name, symbol):
134
+ em_a_stock_info_df = em_stock_info_api.get_a_stock_info()
135
+ if symbol is not None:
136
+ em_a_stock_info_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'] == symbol]
137
+ em_a_stock_info_df = common_service_fun_api.add_pre_prefix(em_a_stock_info_df)
138
+ # 或等效写法 df['A'].str[0:6]
139
+
140
+ fail_list = []
141
+
142
+ xue_qiu_cookie = cookie_info_service.get_xue_qiu_cookie()
143
+ report_type_list = ['income', 'balance', 'cash_flow']
144
+ for stock_one in em_a_stock_info_df.itertuples():
145
+ fail_list = save_one_symbol_data(stock_one, report_type_list, xue_qiu_cookie, False, fail_list, report_name,
146
+ True)
147
+
148
+ handle_number = 0
149
+ # 处理失败的
150
+ while len(fail_list) > 0:
151
+ fail_df = em_a_stock_info_df.loc[em_a_stock_info_df['symbol'].isin(fail_list)]
152
+ for fail_one in fail_df.itertuples():
153
+ fail_list = save_one_symbol_data(fail_one, report_type_list, xue_qiu_cookie, False, fail_list, report_name,
154
+ True)
155
+ handle_number = handle_number + 1
156
+ if handle_number > 10:
157
+ break
158
+
159
+
160
+ if __name__ == '__main__':
161
+ sync_all_stocks_report()
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -2,18 +2,23 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
- import mns_common.api.em.east_money_stock_hk_api as east_money_stock_hk_api
8
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
9
9
  import akshare as ak
10
10
  import mns_common.constant.db_name_constant as db_name_constant
11
11
  from mns_common.db.MongodbUtil import MongodbUtil
12
+ from functools import lru_cache
13
+ import mns_common.api.hk.ths_hk_company_info_api as ths_hk_company_info_api
14
+ import pandas as pd
12
15
 
13
16
  mongodb_util = MongodbUtil('27017')
14
- COOKIE = 'qgqp_b_id=1e0d79428176ed54bef8434efdc0e8c3; mtp=1; ct=QVRY_s8Tiag1WfK2tSW2n03qpsX-PD8aH_rIjKVooawX8K33UVnpIofK088lD1lguWlE_OEIpQwn3PJWFPhHvSvyvYr4Zka3l4vxtZfH1Uikjtyy9z1H4Swo0rQzMKXncVzBXiOo5TjE-Dy9fcoG3ZF7UVdQ35jp_cFwzOlpK5Y; ut=FobyicMgeV51lVMr4ZJXvn-72bp0oeSOvtzifFY_U7kBFtR6og4Usd-VtBM5XBBvHq0lvd9xXkvpIqWro9EDKmv6cbKOQGyawUSMcKVP57isZCaM7lWQ6jWXajvTfvV4mIR-W_MZNK8VY0lL9W4qNMniJ6PBn_gkJsSAJCadmsyI9cxmjx--gR4m54pdF_nie_y4iWHys83cmWR2R7Bt1KKqB25OmkfCQTJJqIf7QsqangVGMUHwMC39Z9QhrfCFHKVNrlqS503O6b9GitQnXtvUdJhCmomu; pi=4253366368931142%3Bp4253366368931142%3B%E8%82%A1%E5%8F%8B9x56I87727%3BYNigLZRW%2FzMdGgVDOJbwReDWnTPHl51dB0gQLiwaCf1XY98mlJYx6eJbsoYr5Nie%2BX1L%2BzaMsec99KkX%2BT29Ds1arfST7sIBXxjUQ3dp11IPUnXy64PaBFRTHzMRWnCFJvvhc%2FAI41rXSGXolC8YMxI%2BvyPS%2BuErwgOVjC5vvsIiKeO7TLyKkhqqQJPX%2F7RWC5Sf3QLh%3Bdwjn4Xho10%2FKjqOgTWs%2FJF4%2FkdKzeuBwM8sz9aLvJovejAkCAyGMyGYA6AE67Xk2Ki7x8zdfBifF2DG%2Fvf2%2BXAYN8ZVISSEWTIXh32Z5MxEacK4JBTkqyiD93e1vFBOFQ82BqaiVmntUq0V6FrTUHGeh1gG5Sg%3D%3D; uidal=4253366368931142%e8%82%a1%e5%8f%8b9x56I87727; sid=170711377; vtpst=|; quote_lt=1; websitepoptg_api_time=1715777390466; emshistory=%5B%22%E8%BD%AC%E5%80%BA%E6%A0%87%22%2C%22%E8%BD%AC%E5%80%BA%E6%A0%87%E7%9A%84%22%5D; st_si=00364513876913; st_asi=delete; HAList=ty-116-00700-%u817E%u8BAF%u63A7%u80A1%2Cty-1-688695-%u4E2D%u521B%u80A1%u4EFD%2Cty-1-600849-%u4E0A%u836F%u8F6C%u6362%2Cty-1-603361-%u6D59%u6C5F%u56FD%u7965%2Cty-1-603555-ST%u8D35%u4EBA%2Cty-0-000627-%u5929%u8302%u96C6%u56E2%2Cty-0-002470-%u91D1%u6B63%u5927%2Cty-0-832876-%u6167%u4E3A%u667A%u80FD%2Cty-0-300059-%u4E1C%u65B9%u8D22%u5BCC%2Cty-107-CWB-%u53EF%u8F6C%u503AETF-SPDR; st_pvi=26930719093675; st_sp=2024-04-28%2017%3A27%3A05; st_inirUrl=https%3A%2F%2Fcn.bing.com%2F; st_sn=23; st_psi=20240517111108288-113200301321-2767127768'
17
+ from loguru import logger
15
18
 
16
19
 
20
+ # 获取陆股通的列表
21
+ @lru_cache(maxsize=None)
17
22
  def get_hk_ggt_component():
18
23
  stock_hk_ggt_components_em_df = ak.stock_hk_ggt_components_em()
19
24
  stock_hk_ggt_components_em_df = stock_hk_ggt_components_em_df.rename(columns={
@@ -24,9 +29,26 @@ def get_hk_ggt_component():
24
29
  return stock_hk_ggt_components_em_df
25
30
 
26
31
 
32
+ # 获取em cookie
33
+ @lru_cache(maxsize=None)
34
+ def get_em_cookie():
35
+ query = {"type": "em_cookie"}
36
+ stock_account_info = mongodb_util.find_query_data(db_name_constant.STOCK_ACCOUNT_INFO, query)
37
+ cookie = list(stock_account_info['cookie'])[0]
38
+ return cookie
39
+
40
+
41
+ @lru_cache(maxsize=None)
42
+ def get_ths_cookie():
43
+ query = {"type": "ths_cookie"}
44
+ stock_account_info = mongodb_util.find_query_data(db_name_constant.STOCK_ACCOUNT_INFO, query)
45
+ cookie = list(stock_account_info['cookie'])[0]
46
+ return cookie
47
+
48
+
27
49
  # https://quote.eastmoney.com/center/gridlist.html#hk_stocks
28
50
  def sync_hk_company_info():
29
- hk_real_time_df = east_money_stock_hk_api.hk_real_time_quotes(COOKIE)
51
+ hk_real_time_df = em_stock_info_api.get_hk_stock_info()
30
52
 
31
53
  hk_real_time_df = hk_real_time_df[[
32
54
  "symbol",
@@ -51,9 +73,31 @@ def sync_hk_company_info():
51
73
  hk_real_time_df['_id'] = hk_real_time_df['symbol']
52
74
 
53
75
  hk_real_time_df.fillna(0, inplace=True)
76
+ mongodb_util.remove_all_data(db_name_constant.COMPANY_INFO_HK)
77
+ hk_real_time_df = hk_real_time_df.sort_values(by=['hk_ggt'], ascending=False)
78
+ for stock_one in hk_real_time_df.itertuples():
79
+ try:
80
+ symbol = stock_one.symbol
81
+ ths_cookie = get_ths_cookie()
82
+ company_hk_df = ths_hk_company_info_api.get_hk_company_info(symbol, ths_cookie)
83
+
84
+ company_hk_df = company_hk_df.rename(columns={
85
+ "industry": "industry_detail",
86
+ "list_date": "list_date_str",
87
+ })
88
+
89
+ hk_real_time_one_df = hk_real_time_df.loc[hk_real_time_df['symbol'] == symbol]
90
+
91
+ company_hk_df = company_hk_df.set_index(['symbol'], drop=True)
92
+ hk_real_time_one_df = hk_real_time_one_df.set_index(['symbol'], drop=False)
93
+ company_hk_df = pd.merge(company_hk_df, hk_real_time_one_df, how='outer',
94
+ left_index=True, right_index=True)
54
95
 
55
- mongodb_util.save_mongo(hk_real_time_df, db_name_constant.COMPANY_INFO_HK)
96
+ mongodb_util.save_mongo(company_hk_df, db_name_constant.COMPANY_INFO_HK)
97
+ except BaseException as e:
98
+ logger.error("同步港股公司信息异常:{},{}", symbol, e)
56
99
 
57
100
 
58
101
  if __name__ == '__main__':
102
+ get_hk_ggt_component()
59
103
  sync_hk_company_info()
@@ -0,0 +1,68 @@
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
+
9
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
10
+ import akshare as ak
11
+ import mns_common.constant.db_name_constant as db_name_constant
12
+ from mns_common.db.MongodbUtil import MongodbUtil
13
+ from functools import lru_cache
14
+ import mns_common.component.zt.zt_common_service_api as zt_common_service_api
15
+
16
+ mongodb_util = MongodbUtil('27017')
17
+
18
+
19
+ # 获取陆股通的列表
20
+ @lru_cache(maxsize=None)
21
+ def get_hk_ggt_component():
22
+ stock_hk_ggt_components_em_df = ak.stock_hk_ggt_components_em()
23
+ stock_hk_ggt_components_em_df = stock_hk_ggt_components_em_df.rename(columns={
24
+ "序号": "index",
25
+ "代码": "symbol",
26
+ "名称": "name"
27
+ })
28
+ return stock_hk_ggt_components_em_df
29
+
30
+
31
+ # 获取em cookie
32
+ @lru_cache(maxsize=None)
33
+ def get_em_cookie():
34
+ query = {"type": "em_cookie"}
35
+ stock_account_info = mongodb_util.find_query_data(db_name_constant.STOCK_ACCOUNT_INFO, query)
36
+ cookie = list(stock_account_info['cookie'])[0]
37
+ return cookie
38
+
39
+
40
+ def sync_hk_company_industry():
41
+ hk_real_time_df = em_stock_info_api.get_hk_stock_info()
42
+
43
+ hk_real_time_df = hk_real_time_df[[
44
+ "symbol",
45
+ "name",
46
+ "chg",
47
+ "total_mv",
48
+ "flow_mv",
49
+ "list_date",
50
+ "industry",
51
+ "amount",
52
+ "now_price"
53
+ ]]
54
+ hk_real_time_df = hk_real_time_df.loc[(hk_real_time_df['total_mv'] != '-')]
55
+ hk_real_time_df['total_mv'] = hk_real_time_df['total_mv'].astype(float)
56
+ hk_real_time_df['flow_mv'] = hk_real_time_df['flow_mv'].astype(float)
57
+ hk_real_time_df = hk_real_time_df.loc[hk_real_time_df['total_mv'] != 0]
58
+
59
+ hk_real_time_df.loc[hk_real_time_df['industry'] == '-', 'industry'] = '其他'
60
+
61
+ group_industry_df = zt_common_service_api.group_by_industry(hk_real_time_df, 'industry')
62
+ group_industry_df['_id'] = group_industry_df['industry']
63
+ mongodb_util.remove_all_data(db_name_constant.HK_COMPANY_INDUSTRY)
64
+ mongodb_util.save_mongo(group_industry_df, db_name_constant.HK_COMPANY_INDUSTRY)
65
+
66
+
67
+ if __name__ == '__main__':
68
+ sync_hk_company_industry()
@@ -0,0 +1,7 @@
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)
@@ -0,0 +1,7 @@
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)
@@ -0,0 +1,58 @@
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.app.ths_concept_index_app as ths_concept_index_app
9
+ from datetime import datetime
10
+ import mns_common.component.trade_date.trade_date_common_service_api as trade_date_common_service_api
11
+ import mns_common.utils.date_handle_util as date_handle_util
12
+ import mns_common.utils.data_frame_util as data_frame_util
13
+ import pandas as pd
14
+ import mns_common.component.common_service_fun_api as common_service_fun_api
15
+
16
+
17
+ # 通过api 获取ths行业和指数
18
+ def get_ths_index_by_api(query_type):
19
+ now_date = datetime.now()
20
+ hour = now_date.hour
21
+ minute = now_date.minute
22
+ now_str_day = now_date.strftime('%Y-%m-%d')
23
+
24
+ is_trade_day = trade_date_common_service_api.is_trade_day(now_str_day)
25
+
26
+ if bool(1 - is_trade_day):
27
+ last_trade_day = trade_date_common_service_api.get_before_trade_date(now_str_day, 1)
28
+ begin_time = date_handle_util.no_slash_date(last_trade_day) + '093000'
29
+ end_time = date_handle_util.no_slash_date(last_trade_day) + '150000'
30
+ else:
31
+ if hour < 9 or (hour == 9 and minute <= 25):
32
+ last_trade_day = trade_date_common_service_api.get_before_trade_date(now_str_day, 2)
33
+ begin_time = date_handle_util.no_slash_date(last_trade_day) + '093000'
34
+ end_time = date_handle_util.no_slash_date(last_trade_day) + '150000'
35
+ else:
36
+ begin_time = date_handle_util.no_slash_date(now_str_day) + '093000'
37
+ if hour == 9:
38
+ hour = '0' + str(hour)
39
+ end_time = date_handle_util.no_slash_date(now_str_day) + str(hour) + str(minute) + '00'
40
+ elif (hour == 11 and minute >= 30) or (hour == 12):
41
+ end_time = date_handle_util.no_slash_date(now_str_day) + '113000'
42
+ elif hour >= 15:
43
+ end_time = date_handle_util.no_slash_date(now_str_day) + '150000'
44
+ else:
45
+ end_time = date_handle_util.no_slash_date(now_str_day) + str(hour) + str(minute) + '00'
46
+
47
+ df = ths_concept_index_app.get_ths_concept_his_info(begin_time, end_time, 500, query_type)
48
+ if data_frame_util.is_empty(df):
49
+ return pd.DataFrame()
50
+ df['turnover'] = round(df['turnover'] / common_service_fun_api.HUNDRED_MILLION, 1)
51
+ df['net_inflow_of_main_force'] = round(df['net_inflow_of_main_force'] / common_service_fun_api.TEN_THOUSAND, 1)
52
+ df.fillna('', inplace=True)
53
+ return df
54
+
55
+
56
+ if __name__ == '__main__':
57
+ df_industry = get_ths_index_by_api(1)
58
+ print(df_industry)
@@ -0,0 +1,68 @@
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_scheduler.industry.ths.ths_industry_index_service as ths_industry_index_service
9
+ from mns_common.db.MongodbUtil import MongodbUtil
10
+ import time
11
+ from datetime import datetime
12
+ from loguru import logger
13
+ import mns_common.utils.data_frame_util as data_frame_util
14
+ import mns_common.api.ths.concept.app.ths_concept_detail_app as ths_concept_detail_app
15
+
16
+ mongodb_util = MongodbUtil('27017')
17
+ import mns_common.constant.db_name_constant as db_name_constant
18
+
19
+
20
+ # 同步同花顺行业指数
21
+ def sync_ths_industry_index():
22
+ ths_industry_index_df = ths_industry_index_service.get_ths_index_by_api(1)
23
+ if data_frame_util.is_empty(ths_industry_index_df):
24
+ return None
25
+ ths_industry_index_df['_id'] = ths_industry_index_df['block_code']
26
+ ths_industry_index_df = ths_industry_index_df[[
27
+ '_id',
28
+ 'turnover',
29
+ 'block_market',
30
+ 'block_code',
31
+ 'block_name',
32
+ 'net_inflow_of_main_force',
33
+ 'chg'
34
+ ]]
35
+ now_date = datetime.now()
36
+ str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
37
+ ths_industry_index_df['str_now_date'] = str_now_date
38
+ mongodb_util.save_mongo(ths_industry_index_df, db_name_constant.THS_INDUSTRY_LIST)
39
+
40
+
41
+ def sync_ths_industry_detail():
42
+ ths_industry_list_df = mongodb_util.find_all_data(db_name_constant.THS_INDUSTRY_LIST)
43
+ for industry_one in ths_industry_list_df.itertuples():
44
+ try:
45
+ time.sleep(1)
46
+ now_date = datetime.now()
47
+ str_now_date = now_date.strftime('%Y-%m-%d %H:%M:%S')
48
+
49
+ ths_industry_symbol_detail_df = ths_concept_detail_app.get_ths_concept_detail_by_app(
50
+ industry_one.block_code)
51
+ ths_industry_symbol_detail_df = ths_industry_symbol_detail_df.rename(
52
+ columns={"concept_code": 'ths_industry_code',
53
+ "concept_name": 'ths_industry_name',
54
+ })
55
+ if data_frame_util.is_empty(ths_industry_symbol_detail_df):
56
+ continue
57
+ ths_industry_symbol_detail_df['str_now_date'] = str_now_date
58
+ ths_industry_symbol_detail_df['_id'] = ths_industry_symbol_detail_df['symbol']
59
+ mongodb_util.save_mongo(ths_industry_symbol_detail_df, db_name_constant.THS_STOCK_INDUSTRY_DETAIL)
60
+ logger.info("同步ths行业股票详情:{}", industry_one.block_name)
61
+
62
+ except BaseException as e:
63
+ logger.error("同步ths行业股票详情异常:{}", e)
64
+
65
+
66
+ if __name__ == '__main__':
67
+ sync_ths_industry_index()
68
+ sync_ths_industry_detail()
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
@@ -2,7 +2,7 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  # !/usr/bin/env python
@@ -2,7 +2,7 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  # !/usr/bin/env python
@@ -2,13 +2,13 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)
8
8
  import akshare as ak
9
9
  import mns_common.utils.data_frame_util as data_frame_util
10
10
  import pandas as pd
11
- import mns_common.api.em.east_money_stock_api as east_money_stock_api
11
+ import mns_common.component.em.em_stock_info_api as em_stock_info_api
12
12
  import mns_common.component.company.company_common_service_api as company_common_service_api
13
13
  from loguru import logger
14
14
  from datetime import datetime
@@ -119,18 +119,18 @@ def save_sh_stock_uid():
119
119
 
120
120
 
121
121
  # 同步所有互动问题
122
- def sync_all_interactive_questions(symbol_list):
122
+ def sync_symbols_interactive_questions(symbol_list):
123
123
  # 同步互动易映射
124
- save_sh_stock_uid()
125
-
126
- real_time_quotes_all_stocks = east_money_stock_api.get_real_time_quotes_all_stocks()
124
+ if len(symbol_list) == 0:
125
+ save_sh_stock_uid()
126
+ real_time_quotes_all_stocks = em_stock_info_api.get_a_stock_info()
127
127
  de_list_company_symbols = company_common_service_api.get_de_list_company()
128
128
  real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
129
129
  ~(real_time_quotes_all_stocks['symbol'].isin(de_list_company_symbols))]
130
130
  real_time_quotes_all_stocks = common_service_fun_api.classify_symbol(real_time_quotes_all_stocks)
131
131
  real_time_quotes_all_stocks = real_time_quotes_all_stocks.sort_values(by=['chg'], ascending=False)
132
132
  fail_symbol_list = []
133
- if symbol_list is not None:
133
+ if len(symbol_list) != 0:
134
134
  real_time_quotes_all_stocks = real_time_quotes_all_stocks.loc[
135
135
  real_time_quotes_all_stocks['symbol'].isin(symbol_list)]
136
136
  for stock_one in real_time_quotes_all_stocks.itertuples():
@@ -149,6 +149,8 @@ def sync_all_interactive_questions(symbol_list):
149
149
 
150
150
  else:
151
151
  continue
152
+ if data_frame_util.is_empty(stock_irm_cninfo_df):
153
+ continue
152
154
  stock_irm_cninfo_df['sync_time'] = str_now_date
153
155
  stock_irm_cninfo_df['str_day'] = str_day
154
156
  stock_irm_cninfo_df.drop_duplicates('_id', keep='last', inplace=True)
@@ -162,8 +164,7 @@ def sync_all_interactive_questions(symbol_list):
162
164
  stock_irm_cninfo_df.loc[
163
165
  stock_irm_cninfo_df['question_time'].str.contains('分钟前', na=False), 'answer_time'] = str_now_date
164
166
  stock_irm_cninfo_df['valid'] = True
165
- stock_irm_cninfo_df = stock_irm_cninfo_df.dropna(subset=['answer_content'])
166
- stock_irm_cninfo_df = stock_irm_cninfo_df[stock_irm_cninfo_df['answer_content'] != '']
167
+ stock_irm_cninfo_df['answer_content'].fillna('')
167
168
  # 保存新增数据
168
169
  save_new_data(stock_irm_cninfo_df)
169
170
  logger.info("完成同步互动回答到:{}", stock_one.symbol)
@@ -173,13 +174,12 @@ def sync_all_interactive_questions(symbol_list):
173
174
  logger.error("同步互动问题出现异常:{},{}", stock_one.symbol, e)
174
175
 
175
176
 
176
-
177
177
  def save_new_data(stock_irm_cninfo_df):
178
178
  if data_frame_util.is_empty(stock_irm_cninfo_df):
179
179
  return None
180
180
  else:
181
181
  irm_id_list = list(stock_irm_cninfo_df['_id'])
182
- query = {"_id": {"$in": irm_id_list}}
182
+ query = {"_id": {"$in": irm_id_list}, 'answer_content': {"$ne": ''}}
183
183
  query_field = {"_id": 1}
184
184
 
185
185
  exist_df = mongodb_util.find_query_data_choose_field(db_name_constant.STOCK_INTERACTIVE_QUESTION, query,
@@ -189,10 +189,12 @@ def save_new_data(stock_irm_cninfo_df):
189
189
  else:
190
190
  new_df = stock_irm_cninfo_df.loc[~(stock_irm_cninfo_df['_id'].isin(list(exist_df['_id'])))]
191
191
  if data_frame_util.is_not_empty(new_df):
192
- mongodb_util.insert_mongo(new_df, db_name_constant.STOCK_INTERACTIVE_QUESTION)
192
+ mongodb_util.save_mongo(new_df, db_name_constant.STOCK_INTERACTIVE_QUESTION)
193
193
 
194
194
 
195
195
  if __name__ == '__main__':
196
+ sync_symbols_interactive_questions([])
197
+ get_stock_irm_cninfo_sh_api('688778')
196
198
  fail_symbol_list_01 = ['000638', '002886', '688778', '688766', '688733', '688778', '688793', '688787']
197
199
  # get_stock_irm_cninfo_sh_api('603633')
198
- sync_all_interactive_questions(None)
200
+ # sync_symbols_interactive_questions(None)
@@ -2,6 +2,6 @@ import sys
2
2
  import os
3
3
 
4
4
  file_path = os.path.abspath(__file__)
5
- end = file_path.index('mns') + 16
5
+ end = file_path.index('mns') + 17
6
6
  project_path = file_path[0:end]
7
7
  sys.path.append(project_path)