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.
- mns_scheduler/__init__.py +1 -3
- mns_scheduler/company_info/announce/company_announce_sync_service.py +65 -0
- mns_scheduler/company_info/{company_info_sync_api.py → base/sync_company_base_info_api.py} +239 -227
- mns_scheduler/company_info/base/sync_company_hold_info_api.py +37 -0
- mns_scheduler/company_info/base/sync_company_product_area_industry.py +161 -0
- mns_scheduler/company_info/clean/company_info_clean_api.py +133 -0
- mns_scheduler/company_info/constant/company_constant_data.py +497 -0
- mns_scheduler/company_info/{de_list_stock_service.py → de_list_stock/de_list_stock_service.py} +1 -1
- mns_scheduler/company_info/em_stock_info/__init__.py +7 -0
- mns_scheduler/company_info/em_stock_info/sync_em_stock_info_sync.py +80 -0
- mns_scheduler/company_info/remark/__init__.py +7 -0
- mns_scheduler/company_info/remark/company_remark_info_sync.py +46 -0
- mns_scheduler/concept/clean/kpl_concept_clean_api.py +1 -1
- mns_scheduler/concept/clean/ths_concept_clean_api.py +74 -51
- mns_scheduler/concept/ths/common/ths_concept_sync_common_api.py +112 -56
- mns_scheduler/concept/ths/common/ths_concept_update_common_api.py +6 -6
- mns_scheduler/concept/ths/detaill/__init__.py +0 -0
- mns_scheduler/concept/ths/detaill/ths_concept_detail_api.py +226 -0
- mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_new_index_api.py +169 -0
- mns_scheduler/concept/ths/update_concept_info/sync_one_concept_all_symbols_api.py +11 -23
- mns_scheduler/concept/ths/update_concept_info/sync_one_symbol_all_concepts_api.py +19 -15
- mns_scheduler/db/col_move_service.py +10 -7
- mns_scheduler/db/db_status.py +1 -1
- mns_scheduler/db/script/__init__.py +7 -0
- mns_scheduler/db/script/col_move_script.py +45 -0
- mns_scheduler/db/script/db_move/__init__.py +7 -0
- mns_scheduler/db/script/db_move/col_move_one_service.py +34 -0
- mns_scheduler/db/script/sync/__init__.py +7 -0
- mns_scheduler/db/script/sync/local_mongo_util.py +231 -0
- mns_scheduler/db/script/sync/remote_data_sync_to_local.py +105 -0
- mns_scheduler/db/script/sync/remote_mongo_util.py +306 -0
- mns_scheduler/db/script/sync/sync_hui_ce_test_data.py +80 -0
- mns_scheduler/db/script/sync/sync_hui_ce_test_data_01.py +69 -0
- mns_scheduler/db/script/update/__init__.py +7 -0
- mns_scheduler/db/script/update/update_col_field.py +36 -0
- mns_scheduler/finance/__init__.py +1 -1
- mns_scheduler/finance/{em_financial_asset_liability_sync_service_api.py → em/em_financial_asset_liability_sync_service_api.py} +3 -3
- mns_scheduler/finance/{em_financial_profit_sync_service_api.py → em/em_financial_profit_sync_service_api.py} +30 -25
- mns_scheduler/finance/{finance_common_api.py → em/finance_common_api.py} +4 -4
- mns_scheduler/finance/sync_financial_report_service_task.py +202 -0
- mns_scheduler/finance/xue_qiu/down_load_xueqiu_report_api.py +77 -0
- mns_scheduler/finance/xue_qiu/sync_xue_qiu_fiance_data.py +161 -0
- mns_scheduler/hk/__init__.py +1 -1
- mns_scheduler/hk/hk_company_info_sync_service_api.py +49 -5
- mns_scheduler/hk/hk_industry_info_sync_service_api.py +68 -0
- mns_scheduler/industry/__init__.py +7 -0
- mns_scheduler/industry/ths/__init__.py +7 -0
- mns_scheduler/industry/ths/ths_industry_index_service.py +58 -0
- mns_scheduler/industry/ths/ths_industry_sync_service.py +68 -0
- mns_scheduler/irm/__init__.py +1 -1
- mns_scheduler/irm/api/__init__.py +1 -1
- mns_scheduler/irm/api/sh_stock_sns_sse_info_api.py +1 -1
- mns_scheduler/irm/api/sz_stock_sns_sse_info_api.py +1 -1
- mns_scheduler/irm/stock_irm_cninfo_service.py +15 -13
- mns_scheduler/k_line/clean/daily/__init__.py +1 -1
- mns_scheduler/k_line/clean/daily/daily_k_line_clean_common_service.py +57 -7
- mns_scheduler/k_line/clean/daily/daily_k_line_service.py +16 -3
- mns_scheduler/k_line/clean/k_line_info_clean_impl.py +3 -2
- mns_scheduler/k_line/clean/k_line_info_clean_task.py +42 -31
- mns_scheduler/k_line/clean/week_month/__init__.py +1 -1
- mns_scheduler/k_line/clean/week_month/normal_week_month_k_line_service.py +125 -27
- mns_scheduler/k_line/clean/week_month/sub_new_week_month_k_line_service.py +72 -17
- mns_scheduler/k_line/common/__init__.py +7 -0
- mns_scheduler/k_line/common/k_line_common_api.py +188 -0
- mns_scheduler/k_line/hot_stocks/__init__.py +1 -1
- mns_scheduler/k_line/hot_stocks/recent_hot_stocks_clean_service.py +1 -1
- mns_scheduler/k_line/month_week_daily/bfq_k_line_sync.py +77 -0
- mns_scheduler/k_line/{sync → month_week_daily}/daily_week_month_line_sync.py +14 -14
- mns_scheduler/k_line/sync_status/__init__.py +7 -0
- mns_scheduler/k_line/sync_status/k_line_sync_status_check.py +54 -0
- mns_scheduler/k_line/test/__init__.py +7 -0
- mns_scheduler/k_line/test/k_line_info_clean_his_data.py +41 -0
- mns_scheduler/k_line/year_quarter/__init__.py +7 -0
- mns_scheduler/k_line/year_quarter/year_quarter_line_sync.py +76 -0
- mns_scheduler/kpl/selection/symbol/sync_best_choose_symbol.py +4 -2
- mns_scheduler/kpl/selection/symbol/sync_kpl_concept_symbol_choose_reason_api.py +108 -0
- mns_scheduler/kpl/selection/total/sync_kpl_best_total_sync_api.py +12 -7
- mns_scheduler/lhb/__init__.py +1 -1
- mns_scheduler/lhb/stock_lhb_sync_service.py +1 -1
- mns_scheduler/open/__init__.py +1 -1
- mns_scheduler/open/sync_one_day_open_data_to_db_service.py +6 -22
- mns_scheduler/risk/__init__.py +1 -1
- mns_scheduler/risk/compliance/__init__.py +0 -0
- mns_scheduler/risk/compliance/undisclosed_annual_report_api.py +71 -0
- mns_scheduler/risk/financial/__init__.py +0 -0
- mns_scheduler/risk/financial/annual_report_audit_check_api.py +54 -0
- mns_scheduler/risk/financial/net_assets_check_api.py +75 -0
- mns_scheduler/risk/financial/profit_income_check_api.py +80 -0
- mns_scheduler/risk/financial/stock_equity_mortgage_check_api.py +1 -0
- mns_scheduler/risk/financial_report_risk_check_api.py +42 -0
- mns_scheduler/risk/major_violations/__init__.py +0 -0
- mns_scheduler/risk/{register_and_investigate_stock_sync_api.py → major_violations/register_and_investigate_stock_sync_api.py} +17 -8
- mns_scheduler/risk/self/__init__.py +0 -0
- mns_scheduler/risk/{wei_pan_stock_api.py → self/wei_pan_stock_api.py} +10 -4
- mns_scheduler/risk/test/__init__.py +7 -0
- mns_scheduler/{finance → risk}/test/fix_blask_list.py +6 -10
- mns_scheduler/risk/transactions/__init__.py +0 -0
- mns_scheduler/risk/transactions/transactions_check_api.py +183 -0
- mns_scheduler/self_choose/__init__.py +7 -0
- mns_scheduler/self_choose/ths_self_choose_service.py +158 -0
- mns_scheduler/trade/auto_ipo_buy_api.py +2 -2
- mns_scheduler/trade/auto_login/__init__.py +7 -0
- mns_scheduler/trade/auto_login/trader_auto_service.py +32 -0
- mns_scheduler/trade/auto_sell_service_api.py +10 -8
- mns_scheduler/trade/balance/__init__.py +7 -0
- mns_scheduler/trade/balance/ths_account_balance_service.py +7 -0
- mns_scheduler/trade/sync_position_api.py +41 -8
- mns_scheduler/trade/task/__init__.py +7 -0
- mns_scheduler/trade/task/trader_task_service.py +65 -0
- mns_scheduler/trade/tfp/__init__.py +7 -0
- mns_scheduler/trade/tfp/stock_tfp_info_sync.py +56 -0
- mns_scheduler/zb/stock_zb_pool_sync.py +1 -15
- mns_scheduler/zt/high_chg/sync_high_chg_pool_service.py +2 -3
- mns_scheduler/zt/high_chg/sync_high_chg_real_time_quotes_service.py +12 -8
- mns_scheduler/zt/open_data/kcx_high_chg_open_data_sync.py +10 -25
- mns_scheduler/zt/script/__init__.py +1 -1
- mns_scheduler/zt/script/fix_error_deal_day.py +41 -0
- mns_scheduler/zt/script/kcx_high_chg_open_his_data_handle.py +2 -11
- mns_scheduler/zt/script/sync_high_chg_pool_his_data.py +2 -2
- mns_scheduler/zt/script/sync_now_higt_chg_zt.py +43 -0
- mns_scheduler/zt/zt_pool/em_zt_pool_sync_api.py +413 -0
- mns_scheduler/zt/zt_pool/ths_zt_pool_sync_api.py +193 -0
- mns_scheduler/zt/zt_pool/update_null_zt_reason_api.py +58 -0
- mns_scheduler/zz_task/compensation/__init__.py +0 -0
- mns_scheduler/zz_task/compensation/compensate_task.py +161 -0
- mns_scheduler/zz_task/compensation/compensate_task_one_day.py +142 -0
- mns_scheduler/zz_task/data_sync_task.py +271 -121
- {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/METADATA +1 -1
- mns_scheduler-1.4.3.2.dist-info/RECORD +169 -0
- {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/WHEEL +1 -1
- mns_scheduler/backup/app/ths_new_concept_sync_app.py +0 -122
- mns_scheduler/backup/em/em_new_concept_his_sync.py +0 -99
- mns_scheduler/backup/em/em_new_concept_sync_common_api.py +0 -139
- mns_scheduler/backup/em/em_new_concept_sync_web.py +0 -55
- mns_scheduler/backup/wen_cai/wen_cai_concept_sync.py +0 -51
- mns_scheduler/big_deal/ths_big_deal_sync.py +0 -98
- mns_scheduler/company_info/company_constant_data.py +0 -322
- mns_scheduler/concept/ths/sync_new_index/sync_ths_concept_by_ak_api.py +0 -103
- mns_scheduler/concept/ths/sync_new_index/sync_ths_new_concept_by_web_api.py +0 -89
- mns_scheduler/finance/financial_high_risk_stock_clean_service_api.py +0 -202
- mns_scheduler/finance/sync_financial_report_service_api.py +0 -113
- mns_scheduler/real_time/realtime_quotes_now_create_db_index.py +0 -27
- mns_scheduler/real_time/realtime_quotes_now_sync.py +0 -232
- mns_scheduler/risk/stock_equity_mortgage_sync_api.py +0 -32
- mns_scheduler/zt/zt_pool/zt_pool_sync_api.py +0 -151
- mns_scheduler/zz_task/sync_realtime_quotes_task.py +0 -28
- mns_scheduler-1.0.8.7.dist-info/RECORD +0 -112
- /mns_scheduler/{backup/app → company_info/announce}/__init__.py +0 -0
- /mns_scheduler/{backup/em → company_info/base}/__init__.py +0 -0
- /mns_scheduler/{backup/wen_cai → company_info/clean}/__init__.py +0 -0
- /mns_scheduler/{big_deal → company_info/constant}/__init__.py +0 -0
- /mns_scheduler/{real_time → company_info/de_list_stock}/__init__.py +0 -0
- /mns_scheduler/{backup → finance/em}/__init__.py +0 -0
- /mns_scheduler/finance/{test → xue_qiu}/__init__.py +0 -0
- /mns_scheduler/k_line/{sync → month_week_daily}/__init__.py +0 -0
- {mns_scheduler-1.0.8.7.dist-info → mns_scheduler-1.4.3.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
from loguru import logger
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def db_export(db, col):
|
|
12
|
+
cmd = 'F:/mongo/bin/mongodump.exe --host ' + db + ' -d patience -c ' + col + ' -o D:/back'
|
|
13
|
+
os.system(cmd)
|
|
14
|
+
logger.info("export finished:{}", col)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def db_import(db, col):
|
|
18
|
+
cmd = 'F:/mongo/bin/mongorestore.exe --host ' + db + ' -d patience -c ' + col + ' D:/back/patience/' + col + '.bson'
|
|
19
|
+
os.system(cmd)
|
|
20
|
+
|
|
21
|
+
path = 'D:\\back\\patience\\' + col + '.bson'
|
|
22
|
+
cmd_del = 'del /F /S /Q ' + path
|
|
23
|
+
os.system(cmd_del)
|
|
24
|
+
|
|
25
|
+
logger.info("import finished:{}", col)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def handle_one_col(col_name):
|
|
29
|
+
db_export('127.0.0.1:27017', col_name)
|
|
30
|
+
db_import('127.0.0.1:27019', col_name)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == '__main__':
|
|
34
|
+
handle_one_col('one_minute_k_line_bfq_h')
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 14
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import pymongo
|
|
10
|
+
from mns_common.utils.async_fun import async_fun
|
|
11
|
+
from loguru import logger
|
|
12
|
+
import warnings
|
|
13
|
+
|
|
14
|
+
warnings.filterwarnings("ignore")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LocalMongodbUtil:
|
|
18
|
+
def __init__(self, port):
|
|
19
|
+
self.port = port
|
|
20
|
+
|
|
21
|
+
def get_db(self):
|
|
22
|
+
client = pymongo.MongoClient("mongodb://127.0.0.1:" + '27017' + "/patience")
|
|
23
|
+
return client.patience
|
|
24
|
+
|
|
25
|
+
def group(self, query, coll_name):
|
|
26
|
+
db = self.get_db()
|
|
27
|
+
collection = db[coll_name]
|
|
28
|
+
data = collection.aggregate(query)
|
|
29
|
+
return pd.DataFrame(list(data))
|
|
30
|
+
|
|
31
|
+
def remove_data(self, query, coll_name):
|
|
32
|
+
db = self.get_db()
|
|
33
|
+
collection = db[coll_name]
|
|
34
|
+
return collection.delete_many(query)
|
|
35
|
+
|
|
36
|
+
def exist_data_query(self, coll_name, query):
|
|
37
|
+
db = self.get_db()
|
|
38
|
+
collection = db[coll_name]
|
|
39
|
+
return collection.count(query, limit=1) > 0
|
|
40
|
+
|
|
41
|
+
def find_one(self, coll_name, _id):
|
|
42
|
+
db = self.get_db()
|
|
43
|
+
collection = db[coll_name]
|
|
44
|
+
return collection.find_one({'_id': _id})
|
|
45
|
+
|
|
46
|
+
def find_one_query(self, coll_name, query):
|
|
47
|
+
db = self.get_db()
|
|
48
|
+
collection = db[coll_name]
|
|
49
|
+
return pd.DataFrame(collection.find_one(query), index=[0])
|
|
50
|
+
|
|
51
|
+
def find_all_data(self, coll_name):
|
|
52
|
+
db = self.get_db()
|
|
53
|
+
collection = db[coll_name]
|
|
54
|
+
rows = collection.find({})
|
|
55
|
+
df = pd.DataFrame([basic for basic in rows])
|
|
56
|
+
return df
|
|
57
|
+
|
|
58
|
+
def find_query_data(self, coll_name, query):
|
|
59
|
+
db = self.get_db()
|
|
60
|
+
collection = db[coll_name]
|
|
61
|
+
rows = collection.find(query)
|
|
62
|
+
df = pd.DataFrame(list(rows))
|
|
63
|
+
return df
|
|
64
|
+
|
|
65
|
+
def find_query_data_choose_field(self, coll_name, query, query_field):
|
|
66
|
+
db = self.get_db()
|
|
67
|
+
collection = db[coll_name]
|
|
68
|
+
rows = collection.find(query, query_field)
|
|
69
|
+
df = pd.DataFrame(list(rows))
|
|
70
|
+
return df
|
|
71
|
+
|
|
72
|
+
def find_query_data_list(self, coll_name, query):
|
|
73
|
+
db = self.get_db()
|
|
74
|
+
collection = db[coll_name]
|
|
75
|
+
rows = collection.find(query)
|
|
76
|
+
return list(rows)
|
|
77
|
+
|
|
78
|
+
def find_query_data_list(self, coll_name, query):
|
|
79
|
+
db = self.get_db()
|
|
80
|
+
collection = db[coll_name]
|
|
81
|
+
rows = collection.find(query)
|
|
82
|
+
return list(rows)
|
|
83
|
+
|
|
84
|
+
def remove_all_data(self, database):
|
|
85
|
+
db = self.get_db()
|
|
86
|
+
collection = db[database]
|
|
87
|
+
query = {"_id": {"$ne": "null"}}
|
|
88
|
+
return collection.delete_many(query)
|
|
89
|
+
|
|
90
|
+
def drop_collection(self, database):
|
|
91
|
+
db = self.get_db()
|
|
92
|
+
collection = db[database]
|
|
93
|
+
collection.drop()
|
|
94
|
+
|
|
95
|
+
def ascend_query(self, query, coll_name, field, num):
|
|
96
|
+
db = self.get_db()
|
|
97
|
+
collection = db[coll_name]
|
|
98
|
+
return pd.DataFrame(list(collection.find(query).sort(field, 1).skip(0).limit(num)));
|
|
99
|
+
|
|
100
|
+
def descend_query(self, query, coll_name, field, num):
|
|
101
|
+
db = self.get_db()
|
|
102
|
+
collection = db[coll_name]
|
|
103
|
+
return pd.DataFrame(list(collection.find(query).sort(field, -1).skip(0).limit(num)));
|
|
104
|
+
|
|
105
|
+
def count(self, query, coll_name):
|
|
106
|
+
db = self.get_db()
|
|
107
|
+
collection = db[coll_name]
|
|
108
|
+
return collection.count_documents(query)
|
|
109
|
+
|
|
110
|
+
def query_max(self, query, coll_name, field, num):
|
|
111
|
+
db = self.get_db()
|
|
112
|
+
collection = db[coll_name]
|
|
113
|
+
return pd.DataFrame(list(collection.find(query).sort(field, -1).skip(0).limit(num)));
|
|
114
|
+
|
|
115
|
+
def query_min(self, query, coll_name, field):
|
|
116
|
+
db = self.get_db()
|
|
117
|
+
collection = db[coll_name]
|
|
118
|
+
return pd.DataFrame(list(collection.find(query).sort(field, 1).skip(0).limit(1)));
|
|
119
|
+
|
|
120
|
+
def insert_mongo(self, df, database):
|
|
121
|
+
db = self.get_db()
|
|
122
|
+
if df is None or len(df) == 0:
|
|
123
|
+
return
|
|
124
|
+
collection = db[database]
|
|
125
|
+
# 格式转换
|
|
126
|
+
try:
|
|
127
|
+
df = df.drop_duplicates()
|
|
128
|
+
# df = df.T.drop_duplicates().T
|
|
129
|
+
records = df.to_dict('records')
|
|
130
|
+
collection.insert_many(records)
|
|
131
|
+
except BaseException as e:
|
|
132
|
+
logger.error("插入数据异常:{}", e)
|
|
133
|
+
|
|
134
|
+
def insert_mongo_json(self, json, database):
|
|
135
|
+
db = self.get_db()
|
|
136
|
+
collection = db[database]
|
|
137
|
+
# 格式转换
|
|
138
|
+
try:
|
|
139
|
+
collection.insert_many(json)
|
|
140
|
+
except BaseException as e:
|
|
141
|
+
logger.error("插入数据异常:{}", e)
|
|
142
|
+
|
|
143
|
+
def save_mongo_json(self, json, database):
|
|
144
|
+
db = self.get_db()
|
|
145
|
+
collection = db[database]
|
|
146
|
+
for record in json:
|
|
147
|
+
try:
|
|
148
|
+
collection.save(record)
|
|
149
|
+
except BaseException as e:
|
|
150
|
+
logger.error("保存数据出现异常:{}", e)
|
|
151
|
+
|
|
152
|
+
def save_mongo(self, df, database):
|
|
153
|
+
db = self.get_db()
|
|
154
|
+
if df is None or len(df) == 0:
|
|
155
|
+
return
|
|
156
|
+
collection = db[database]
|
|
157
|
+
# df = df.T.drop_duplicates().T
|
|
158
|
+
# 格式转换
|
|
159
|
+
records = df.to_dict('records')
|
|
160
|
+
for record in records:
|
|
161
|
+
try:
|
|
162
|
+
collection.save(record)
|
|
163
|
+
except BaseException as e:
|
|
164
|
+
logger.error("保存数据出现异常:{},{}", record, e)
|
|
165
|
+
|
|
166
|
+
def save_mongo_no_catch_exception(self, df, database):
|
|
167
|
+
db = self.get_db()
|
|
168
|
+
if df is None or len(df) == 0:
|
|
169
|
+
return
|
|
170
|
+
collection = db[database]
|
|
171
|
+
# df = df.T.drop_duplicates().T
|
|
172
|
+
# 格式转换
|
|
173
|
+
records = df.to_dict('records')
|
|
174
|
+
for record in records:
|
|
175
|
+
collection.save(record)
|
|
176
|
+
|
|
177
|
+
def update_one(self, df, database):
|
|
178
|
+
db = self.get_db()
|
|
179
|
+
condition = {'_id': list(df['_id'])[0]}
|
|
180
|
+
if len(df) == 0:
|
|
181
|
+
return
|
|
182
|
+
collection = db[database]
|
|
183
|
+
collection.update(condition, df)
|
|
184
|
+
|
|
185
|
+
def update_many(self, query, new_values, database):
|
|
186
|
+
db = self.get_db()
|
|
187
|
+
collection = db[database]
|
|
188
|
+
x = collection.update_many(query, new_values)
|
|
189
|
+
return x
|
|
190
|
+
|
|
191
|
+
@async_fun
|
|
192
|
+
def update_one_query(self, query, new_values, database):
|
|
193
|
+
db = self.get_db()
|
|
194
|
+
collection = db[database]
|
|
195
|
+
x = collection.update(query, new_values)
|
|
196
|
+
return x
|
|
197
|
+
|
|
198
|
+
def distinct_field(self, database, field, query):
|
|
199
|
+
db = self.get_db()
|
|
200
|
+
collection = db[database]
|
|
201
|
+
return collection.distinct(field, query)
|
|
202
|
+
|
|
203
|
+
def create_index(self, database, index):
|
|
204
|
+
db = self.get_db()
|
|
205
|
+
collection = db[database]
|
|
206
|
+
collection.create_index(
|
|
207
|
+
index)
|
|
208
|
+
|
|
209
|
+
def aggregate(self, pipeline, database):
|
|
210
|
+
db = self.get_db()
|
|
211
|
+
collection = db[database]
|
|
212
|
+
data = collection.aggregate(pipeline)
|
|
213
|
+
return pd.DataFrame(list(data))
|
|
214
|
+
|
|
215
|
+
def get_col_keys(self, database):
|
|
216
|
+
db = self.get_db()
|
|
217
|
+
collection = db[database]
|
|
218
|
+
keys = collection.find_one().keys()
|
|
219
|
+
return keys
|
|
220
|
+
|
|
221
|
+
# 分页查询 descend 是否降序
|
|
222
|
+
def find_page_skip_data(self, coll_name, page_query, page, page_number, field, descend):
|
|
223
|
+
db = self.get_db()
|
|
224
|
+
collection = db[coll_name]
|
|
225
|
+
if descend:
|
|
226
|
+
sort_tag = -1
|
|
227
|
+
else:
|
|
228
|
+
sort_tag = 1
|
|
229
|
+
rows = collection.find(page_query).sort(field, sort_tag).skip((page - 1) * page_number).limit(page_number)
|
|
230
|
+
df = pd.DataFrame(list(rows))
|
|
231
|
+
return df
|
|
@@ -0,0 +1,105 @@
|
|
|
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.utils.data_frame_util as data_frame_util
|
|
9
|
+
from mns_scheduler.db.script.sync.remote_mongo_util import RemoteMongodbUtil
|
|
10
|
+
from mns_scheduler.db.script.sync.local_mongo_util import LocalMongodbUtil
|
|
11
|
+
from loguru import logger
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
remote_mongodb_util = RemoteMongodbUtil('27017')
|
|
15
|
+
local_mongodb_util = LocalMongodbUtil('27017')
|
|
16
|
+
|
|
17
|
+
col_list = [
|
|
18
|
+
'em_a_stock_info',
|
|
19
|
+
'em_etf_info',
|
|
20
|
+
'em_kzz_info',
|
|
21
|
+
'em_hk_stock_info',
|
|
22
|
+
'company_info',
|
|
23
|
+
'company_remark_info',
|
|
24
|
+
'company_holding_info',
|
|
25
|
+
'industry_concept_remark',
|
|
26
|
+
'trade_date_list',
|
|
27
|
+
'de_list_stock',
|
|
28
|
+
'kpl_best_choose_index',
|
|
29
|
+
'kpl_best_choose_index_detail',
|
|
30
|
+
'realtime_quotes_now_zt_new_kc_open',
|
|
31
|
+
'industry_concept_remark',
|
|
32
|
+
'self_black_stock',
|
|
33
|
+
'self_choose_plate',
|
|
34
|
+
'self_choose_stock',
|
|
35
|
+
'stock_account_info',
|
|
36
|
+
'ths_concept_list',
|
|
37
|
+
'stock_zt_pool_five',
|
|
38
|
+
'ths_stock_concept_detail',
|
|
39
|
+
'stock_high_chg_pool',
|
|
40
|
+
'today_new_concept_list',
|
|
41
|
+
'ths_stock_concept_detail_app'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def remote_data():
|
|
46
|
+
for col in col_list:
|
|
47
|
+
try:
|
|
48
|
+
col_df = remote_mongodb_util.find_all_data(col)
|
|
49
|
+
if data_frame_util.is_not_empty(col_df):
|
|
50
|
+
result = local_mongodb_util.remove_all_data(col)
|
|
51
|
+
if result.acknowledged:
|
|
52
|
+
col_df.replace([np.inf, -np.inf], 0, inplace=True)
|
|
53
|
+
|
|
54
|
+
local_mongodb_util.save_mongo(col_df, col)
|
|
55
|
+
|
|
56
|
+
logger.info("同步集合完成:{}", col)
|
|
57
|
+
except BaseException as e:
|
|
58
|
+
logger.error("同步失败:{},{}", e, col)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def sync_zt_data(str_day):
|
|
62
|
+
col = 'stock_zt_pool'
|
|
63
|
+
try:
|
|
64
|
+
query = {'str_day': str_day}
|
|
65
|
+
col_df = remote_mongodb_util.find_query_data(col, query)
|
|
66
|
+
if data_frame_util.is_not_empty(col_df):
|
|
67
|
+
col_df.replace([np.inf, -np.inf], 0, inplace=True)
|
|
68
|
+
local_mongodb_util.save_mongo(col_df, col)
|
|
69
|
+
|
|
70
|
+
logger.info("同步集合完成:{}", col)
|
|
71
|
+
except BaseException as e:
|
|
72
|
+
logger.error("同步失败:{},{}", e, col)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def sync_open_data():
|
|
76
|
+
query = {"$and": [{'trade_date': {"$gte": "2025-03-21"}}, {'trade_date': {"$lte": "2025-04-02"}}]}
|
|
77
|
+
trade_date_list_df = remote_mongodb_util.find_query_data('trade_date_list', query)
|
|
78
|
+
trade_date_list_df = trade_date_list_df.sort_values(by=['trade_date'], ascending=False)
|
|
79
|
+
for trade_date_one in trade_date_list_df.itertuples():
|
|
80
|
+
try:
|
|
81
|
+
trade_date = trade_date_one.trade_date
|
|
82
|
+
query_01 = {"str_day": trade_date}
|
|
83
|
+
realtime_quotes_now_open_df = remote_mongodb_util.find_query_data('realtime_quotes_now_open', query_01)
|
|
84
|
+
if 'ths_concept_list' in realtime_quotes_now_open_df.columns:
|
|
85
|
+
del realtime_quotes_now_open_df['ths_concept_list']
|
|
86
|
+
local_mongodb_util.insert_mongo(realtime_quotes_now_open_df, 'realtime_quotes_now_open')
|
|
87
|
+
logger.info("同步到:{}", trade_date)
|
|
88
|
+
except BaseException as e:
|
|
89
|
+
logger.error("同步异常:{}", e)
|
|
90
|
+
return trade_date_list_df
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
if __name__ == '__main__':
|
|
94
|
+
sync_zt_data('2025-09-17')
|
|
95
|
+
# sync_zt_data('2025-09-02')
|
|
96
|
+
remote_data()
|
|
97
|
+
# sync_zt_data('2025-08-26')
|
|
98
|
+
# sync_zt_data('2025-08-25')
|
|
99
|
+
# sync_zt_data('2025-08-26')
|
|
100
|
+
# remote_data()
|
|
101
|
+
# sync_zt_data('2025-07-23')
|
|
102
|
+
# sync_zt_data('2025-07-24')
|
|
103
|
+
# sync_zt_data('2025-07-25')
|
|
104
|
+
# sync_open_data()
|
|
105
|
+
# remote_data()
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
file_path = os.path.abspath(__file__)
|
|
5
|
+
end = file_path.index('mns') + 14
|
|
6
|
+
project_path = file_path[0:end]
|
|
7
|
+
sys.path.append(project_path)
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import pymongo
|
|
10
|
+
from mns_common.utils.async_fun import async_fun
|
|
11
|
+
from loguru import logger
|
|
12
|
+
import warnings
|
|
13
|
+
|
|
14
|
+
warnings.filterwarnings("ignore")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RemoteMongodbUtil:
|
|
18
|
+
def __init__(self, port):
|
|
19
|
+
self.port = port
|
|
20
|
+
|
|
21
|
+
def get_db(self):
|
|
22
|
+
client = pymongo.MongoClient("mongodb://100.87.2.149:" + '27017' + "/patience")
|
|
23
|
+
return client.patience
|
|
24
|
+
|
|
25
|
+
def group(self, query, coll_name):
|
|
26
|
+
db = self.get_db()
|
|
27
|
+
collection = db[coll_name]
|
|
28
|
+
data = collection.aggregate(query)
|
|
29
|
+
return pd.DataFrame(list(data))
|
|
30
|
+
|
|
31
|
+
def remove_data(self, query, coll_name):
|
|
32
|
+
db = self.get_db()
|
|
33
|
+
collection = db[coll_name]
|
|
34
|
+
return collection.delete_many(query)
|
|
35
|
+
|
|
36
|
+
def exist_data_query(self, coll_name, query):
|
|
37
|
+
db = self.get_db()
|
|
38
|
+
collection = db[coll_name]
|
|
39
|
+
return collection.count(query, limit=1) > 0
|
|
40
|
+
|
|
41
|
+
def find_one(self, coll_name, _id):
|
|
42
|
+
db = self.get_db()
|
|
43
|
+
collection = db[coll_name]
|
|
44
|
+
return collection.find_one({'_id': _id})
|
|
45
|
+
|
|
46
|
+
def find_one_query(self, coll_name, query):
|
|
47
|
+
db = self.get_db()
|
|
48
|
+
collection = db[coll_name]
|
|
49
|
+
return pd.DataFrame(collection.find_one(query), index=[0])
|
|
50
|
+
|
|
51
|
+
def find_all_data(self, coll_name):
|
|
52
|
+
db = self.get_db()
|
|
53
|
+
collection = db[coll_name]
|
|
54
|
+
rows = collection.find({})
|
|
55
|
+
df = pd.DataFrame([basic for basic in rows])
|
|
56
|
+
return df
|
|
57
|
+
|
|
58
|
+
def find_query_data(self, coll_name, query):
|
|
59
|
+
db = self.get_db()
|
|
60
|
+
collection = db[coll_name]
|
|
61
|
+
rows = collection.find(query)
|
|
62
|
+
df = pd.DataFrame(list(rows))
|
|
63
|
+
return df
|
|
64
|
+
|
|
65
|
+
def find_query_data_choose_field(self, coll_name, query, query_field):
|
|
66
|
+
db = self.get_db()
|
|
67
|
+
collection = db[coll_name]
|
|
68
|
+
rows = collection.find(query, query_field)
|
|
69
|
+
df = pd.DataFrame(list(rows))
|
|
70
|
+
return df
|
|
71
|
+
|
|
72
|
+
def find_query_data_list(self, coll_name, query):
|
|
73
|
+
db = self.get_db()
|
|
74
|
+
collection = db[coll_name]
|
|
75
|
+
rows = collection.find(query)
|
|
76
|
+
return list(rows)
|
|
77
|
+
|
|
78
|
+
def find_query_data_list(self, coll_name, query):
|
|
79
|
+
db = self.get_db()
|
|
80
|
+
collection = db[coll_name]
|
|
81
|
+
rows = collection.find(query)
|
|
82
|
+
return list(rows)
|
|
83
|
+
|
|
84
|
+
def remove_all_data(self, database):
|
|
85
|
+
db = self.get_db()
|
|
86
|
+
collection = db[database]
|
|
87
|
+
query = {"_id": {"$ne": "null"}}
|
|
88
|
+
collection.delete_many(query)
|
|
89
|
+
|
|
90
|
+
def drop_collection(self, database):
|
|
91
|
+
db = self.get_db()
|
|
92
|
+
collection = db[database]
|
|
93
|
+
collection.drop()
|
|
94
|
+
|
|
95
|
+
def ascend_query(self, query, coll_name, field, num):
|
|
96
|
+
db = self.get_db()
|
|
97
|
+
collection = db[coll_name]
|
|
98
|
+
return pd.DataFrame(list(collection.find(query).sort(field, 1).skip(0).limit(num)));
|
|
99
|
+
|
|
100
|
+
def descend_query(self, query, coll_name, field, num):
|
|
101
|
+
db = self.get_db()
|
|
102
|
+
collection = db[coll_name]
|
|
103
|
+
return pd.DataFrame(list(collection.find(query).sort(field, -1).skip(0).limit(num)));
|
|
104
|
+
|
|
105
|
+
def count(self, query, coll_name):
|
|
106
|
+
db = self.get_db()
|
|
107
|
+
collection = db[coll_name]
|
|
108
|
+
return collection.count_documents(query)
|
|
109
|
+
|
|
110
|
+
def query_max(self, query, coll_name, field, num):
|
|
111
|
+
db = self.get_db()
|
|
112
|
+
collection = db[coll_name]
|
|
113
|
+
return pd.DataFrame(list(collection.find(query).sort(field, -1).skip(0).limit(num)));
|
|
114
|
+
|
|
115
|
+
def query_min(self, query, coll_name, field):
|
|
116
|
+
db = self.get_db()
|
|
117
|
+
collection = db[coll_name]
|
|
118
|
+
return pd.DataFrame(list(collection.find(query).sort(field, 1).skip(0).limit(1)));
|
|
119
|
+
|
|
120
|
+
def insert_mongo(self, df, database):
|
|
121
|
+
db = self.get_db()
|
|
122
|
+
if df is None or len(df) == 0:
|
|
123
|
+
return
|
|
124
|
+
collection = db[database]
|
|
125
|
+
# 格式转换
|
|
126
|
+
try:
|
|
127
|
+
df = df.drop_duplicates()
|
|
128
|
+
# df = df.T.drop_duplicates().T
|
|
129
|
+
records = df.to_dict('records')
|
|
130
|
+
collection.insert_many(records)
|
|
131
|
+
except BaseException as e:
|
|
132
|
+
logger.error("插入数据异常:{}", e)
|
|
133
|
+
|
|
134
|
+
def insert_mongo_json(self, json, database):
|
|
135
|
+
db = self.get_db()
|
|
136
|
+
collection = db[database]
|
|
137
|
+
# 格式转换
|
|
138
|
+
try:
|
|
139
|
+
collection.insert_many(json)
|
|
140
|
+
except BaseException as e:
|
|
141
|
+
logger.error("插入数据异常:{}", e)
|
|
142
|
+
|
|
143
|
+
def save_mongo_json(self, json, database):
|
|
144
|
+
db = self.get_db()
|
|
145
|
+
collection = db[database]
|
|
146
|
+
for record in json:
|
|
147
|
+
try:
|
|
148
|
+
collection.save(record)
|
|
149
|
+
except BaseException as e:
|
|
150
|
+
logger.error("保存数据出现异常:{}", e)
|
|
151
|
+
|
|
152
|
+
def save_mongo(self, df, database):
|
|
153
|
+
db = self.get_db()
|
|
154
|
+
if df is None or len(df) == 0:
|
|
155
|
+
return
|
|
156
|
+
collection = db[database]
|
|
157
|
+
# df = df.T.drop_duplicates().T
|
|
158
|
+
# 格式转换
|
|
159
|
+
records = df.to_dict('records')
|
|
160
|
+
for record in records:
|
|
161
|
+
try:
|
|
162
|
+
collection.save(record)
|
|
163
|
+
except BaseException as e:
|
|
164
|
+
logger.error("保存数据出现异常:{},{}", record, e)
|
|
165
|
+
|
|
166
|
+
def save_mongo_no_catch_exception(self, df, database):
|
|
167
|
+
db = self.get_db()
|
|
168
|
+
if df is None or len(df) == 0:
|
|
169
|
+
return
|
|
170
|
+
collection = db[database]
|
|
171
|
+
# df = df.T.drop_duplicates().T
|
|
172
|
+
# 格式转换
|
|
173
|
+
records = df.to_dict('records')
|
|
174
|
+
for record in records:
|
|
175
|
+
collection.save(record)
|
|
176
|
+
|
|
177
|
+
def update_one(self, df, database):
|
|
178
|
+
db = self.get_db()
|
|
179
|
+
condition = {'_id': list(df['_id'])[0]}
|
|
180
|
+
if len(df) == 0:
|
|
181
|
+
return
|
|
182
|
+
collection = db[database]
|
|
183
|
+
collection.update(condition, df)
|
|
184
|
+
|
|
185
|
+
def update_many(self, query, new_values, database):
|
|
186
|
+
db = self.get_db()
|
|
187
|
+
collection = db[database]
|
|
188
|
+
x = collection.update_many(query, new_values)
|
|
189
|
+
return x
|
|
190
|
+
|
|
191
|
+
@async_fun
|
|
192
|
+
def update_one_query(self, query, new_values, database):
|
|
193
|
+
db = self.get_db()
|
|
194
|
+
collection = db[database]
|
|
195
|
+
x = collection.update(query, new_values)
|
|
196
|
+
return x
|
|
197
|
+
|
|
198
|
+
def distinct_field(self, database, field, query):
|
|
199
|
+
db = self.get_db()
|
|
200
|
+
collection = db[database]
|
|
201
|
+
return collection.distinct(field, query)
|
|
202
|
+
|
|
203
|
+
def create_index(self, database, index):
|
|
204
|
+
db = self.get_db()
|
|
205
|
+
collection = db[database]
|
|
206
|
+
collection.create_index(
|
|
207
|
+
index)
|
|
208
|
+
|
|
209
|
+
def aggregate(self, pipeline, database):
|
|
210
|
+
db = self.get_db()
|
|
211
|
+
collection = db[database]
|
|
212
|
+
data = collection.aggregate(pipeline)
|
|
213
|
+
return pd.DataFrame(list(data))
|
|
214
|
+
|
|
215
|
+
def get_col_keys(self, database):
|
|
216
|
+
db = self.get_db()
|
|
217
|
+
collection = db[database]
|
|
218
|
+
keys = collection.find_one().keys()
|
|
219
|
+
return keys
|
|
220
|
+
|
|
221
|
+
# 分页查询 descend 是否降序
|
|
222
|
+
def find_page_skip_data(self, coll_name, page_query, page, page_number, field, descend):
|
|
223
|
+
db = self.get_db()
|
|
224
|
+
collection = db[coll_name]
|
|
225
|
+
if descend:
|
|
226
|
+
sort_tag = -1
|
|
227
|
+
else:
|
|
228
|
+
sort_tag = 1
|
|
229
|
+
rows = collection.find(page_query).sort(field, sort_tag).skip((page - 1) * page_number).limit(page_number)
|
|
230
|
+
df = pd.DataFrame(list(rows))
|
|
231
|
+
return df
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
# if __name__ == '__main__':
|
|
235
|
+
# symbol = '002992'
|
|
236
|
+
# query = {'symbol': symbol,
|
|
237
|
+
# '$and': [{'str_day': {'$gte': '2022-07-06'}}, {'str_day': {'$lte': '2022-11-06'}}]}
|
|
238
|
+
# mongodb_util = MongodbUtil('27017')
|
|
239
|
+
# # num = mongodb_util.count(query, 'stock_zt_pool')
|
|
240
|
+
# # print(num)
|
|
241
|
+
# key = mongodb_util.get_col_keys('stock_zt_pool')
|
|
242
|
+
# print(key)
|
|
243
|
+
#
|
|
244
|
+
# # num = mongodb_util.count(query, 'stock_zt_pool')
|
|
245
|
+
# # print(num)
|
|
246
|
+
#
|
|
247
|
+
# pipeline = [
|
|
248
|
+
# {'$match': {
|
|
249
|
+
# "classification": {'$in': ["K", "C"]},
|
|
250
|
+
# "str_day": {'$gte': "2022-03-16"}}},
|
|
251
|
+
# {'$group': {'_id': "$flow_mv_level", 'count': {'$sum': 1}}}
|
|
252
|
+
# ]
|
|
253
|
+
# result = mongodb_util.aggregate(pipeline, 'realtime_quotes_now_zt_new_kc_open')
|
|
254
|
+
#
|
|
255
|
+
# result = result.sort_values(by=['_id'], ascending=True)
|
|
256
|
+
# print(result)
|
|
257
|
+
from io import StringIO
|
|
258
|
+
import re
|
|
259
|
+
|
|
260
|
+
if __name__ == '__main__':
|
|
261
|
+
mongodb_util = RemoteMongodbUtil('27017')
|
|
262
|
+
#
|
|
263
|
+
# kpl_best_choose_index_df = mongodb_util.find_page_skip_data('kpl_best_choose_index', {"index_class": "sub_index"},
|
|
264
|
+
# 1, 100, 'create_time', True)
|
|
265
|
+
key_word = '高速连接'
|
|
266
|
+
EXCLUDE_INFO_KEY = '股东人数'
|
|
267
|
+
# query = {
|
|
268
|
+
# "$or": [{'question': {"$regex": re.compile(key_word, re.IGNORECASE)}},
|
|
269
|
+
# {'answer_content': {"$regex": re.compile(key_word, re.IGNORECASE)}}],
|
|
270
|
+
# "$and": [{'question': {"$not": re.compile(EXCLUDE_INFO_KEY, re.IGNORECASE)}},
|
|
271
|
+
# {'answer_content': {"$not": re.compile(EXCLUDE_INFO_KEY, re.IGNORECASE)}}],
|
|
272
|
+
# }
|
|
273
|
+
#
|
|
274
|
+
# pipeline = [
|
|
275
|
+
# {'$match': query},
|
|
276
|
+
# {'$group': {'_id': "$symbol", 'count': {'$sum': 1}}}
|
|
277
|
+
# ]
|
|
278
|
+
# result = mongodb_util.aggregate(pipeline, 'stock_interactive_question')
|
|
279
|
+
#
|
|
280
|
+
# result = result.sort_values(by=['_id'], ascending=True)
|
|
281
|
+
# print(result)
|
|
282
|
+
#
|
|
283
|
+
# # ths_new_concept = mongodb_util.find_all_data('ths_new_concept')
|
|
284
|
+
# key = mongodb_util.get_col_keys('company_info')
|
|
285
|
+
# print(key)
|
|
286
|
+
|
|
287
|
+
# mongodb_util.create_index('realtime_quotes_now_open', [("number", 1)])
|
|
288
|
+
# mongodb_util.create_index('realtime_quotes_now_open', [("symbol", 1), ("number", 1)])
|
|
289
|
+
# mongodb_util.create_index('realtime_quotes_now_open', [("str_day", 1)])
|
|
290
|
+
# update_query = {"str_day": "2023-06-30"}
|
|
291
|
+
# mongodb_util.update_many(update_query, {"$set": {"number": 1}}, "realtime_quotes_now_open")
|
|
292
|
+
# query = {"symbol": "000617"}
|
|
293
|
+
# company_info_base = mongodb_util.find_query_data('company_info_base', query)
|
|
294
|
+
# ths_stock_concept_detail = mongodb_util.find_query_data('ths_stock_concept_detail', query)
|
|
295
|
+
# ths_stock_concept_detail = ths_stock_concept_detail[[
|
|
296
|
+
# 'concept_code',
|
|
297
|
+
# 'concept_name',
|
|
298
|
+
# 'str_now_time',
|
|
299
|
+
# 'concept_create_day']]
|
|
300
|
+
# # 去除空格
|
|
301
|
+
# ths_stock_concept_detail['concept_name'] = ths_stock_concept_detail['concept_name'].str.replace(' ', '')
|
|
302
|
+
# company_info_base.loc[:, 'ths_concept_list_info'] = ths_stock_concept_detail.to_string(index=False)
|
|
303
|
+
# for company_one in company_info_base.itertuples():
|
|
304
|
+
# ths_concept_list_info = company_one.ths_concept_list_info
|
|
305
|
+
# ths_concept_list_info_df = pd.read_csv(StringIO(ths_concept_list_info), delim_whitespace=True)
|
|
306
|
+
# print(ths_concept_list_info_df)
|