re-common 10.0.39__py3-none-any.whl → 10.0.41__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.
- re_common/baselibrary/__init__.py +4 -4
- re_common/baselibrary/baseabs/__init__.py +6 -6
- re_common/baselibrary/baseabs/baseabs.py +26 -26
- re_common/baselibrary/database/mbuilder.py +132 -132
- re_common/baselibrary/database/moudle.py +93 -93
- re_common/baselibrary/database/msqlite3.py +194 -194
- re_common/baselibrary/database/mysql.py +169 -169
- re_common/baselibrary/database/sql_factory.py +26 -26
- re_common/baselibrary/mthread/MThreadingRun.py +486 -486
- re_common/baselibrary/mthread/MThreadingRunEvent.py +349 -349
- re_common/baselibrary/mthread/__init__.py +2 -2
- re_common/baselibrary/mthread/mythreading.py +695 -695
- re_common/baselibrary/pakge_other/socks.py +404 -404
- re_common/baselibrary/readconfig/config_factory.py +18 -18
- re_common/baselibrary/readconfig/ini_config.py +317 -317
- re_common/baselibrary/readconfig/toml_config.py +49 -49
- re_common/baselibrary/temporary/envdata.py +36 -36
- re_common/baselibrary/tools/all_requests/aiohttp_request.py +118 -118
- re_common/baselibrary/tools/all_requests/httpx_requet.py +102 -102
- re_common/baselibrary/tools/all_requests/mrequest.py +412 -412
- re_common/baselibrary/tools/all_requests/requests_request.py +81 -81
- re_common/baselibrary/tools/batch_compre/bijiao_batch.py +31 -31
- re_common/baselibrary/tools/contrast_db3.py +123 -123
- re_common/baselibrary/tools/copy_file.py +39 -39
- re_common/baselibrary/tools/db3_2_sizedb3.py +102 -102
- re_common/baselibrary/tools/foreachgz.py +39 -39
- re_common/baselibrary/tools/get_attr.py +10 -10
- re_common/baselibrary/tools/image_to_pdf.py +61 -61
- re_common/baselibrary/tools/java_code_deal.py +139 -139
- re_common/baselibrary/tools/javacode.py +79 -79
- re_common/baselibrary/tools/mdb_db3.py +48 -48
- re_common/baselibrary/tools/merge_file.py +171 -171
- re_common/baselibrary/tools/merge_gz_file.py +165 -165
- re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +42 -42
- re_common/baselibrary/tools/mhdfstools/hdfst.py +42 -42
- re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +38 -38
- re_common/baselibrary/tools/mongo_tools.py +50 -50
- re_common/baselibrary/tools/move_file.py +170 -170
- re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +63 -63
- re_common/baselibrary/tools/move_mongo/move_mongo_table.py +354 -354
- re_common/baselibrary/tools/move_mongo/use_mttf.py +18 -18
- re_common/baselibrary/tools/move_mongo/use_mv.py +93 -93
- re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +125 -125
- re_common/baselibrary/tools/mpandas/pandas_visualization.py +7 -7
- re_common/baselibrary/tools/myparsel.py +104 -104
- re_common/baselibrary/tools/rename_dir_file.py +37 -37
- re_common/baselibrary/tools/sequoiadb_utils.py +398 -398
- re_common/baselibrary/tools/split_line_to_many.py +25 -25
- re_common/baselibrary/tools/stringtodicts.py +33 -33
- re_common/baselibrary/tools/workwechant_bot.py +84 -84
- re_common/baselibrary/utils/baseaiohttp.py +296 -296
- re_common/baselibrary/utils/baseaiomysql.py +87 -87
- re_common/baselibrary/utils/baseallstep.py +191 -191
- re_common/baselibrary/utils/baseavro.py +19 -19
- re_common/baselibrary/utils/baseboto3.py +291 -291
- re_common/baselibrary/utils/basecsv.py +32 -32
- re_common/baselibrary/utils/basedict.py +133 -133
- re_common/baselibrary/utils/basedir.py +241 -241
- re_common/baselibrary/utils/baseencode.py +351 -351
- re_common/baselibrary/utils/baseencoding.py +28 -28
- re_common/baselibrary/utils/baseesdsl.py +86 -86
- re_common/baselibrary/utils/baseexcel.py +264 -264
- re_common/baselibrary/utils/baseexcept.py +109 -109
- re_common/baselibrary/utils/basefile.py +654 -654
- re_common/baselibrary/utils/baseftp.py +214 -214
- re_common/baselibrary/utils/basegzip.py +60 -60
- re_common/baselibrary/utils/basehdfs.py +135 -135
- re_common/baselibrary/utils/basehttpx.py +268 -268
- re_common/baselibrary/utils/baseip.py +87 -87
- re_common/baselibrary/utils/basejson.py +2 -2
- re_common/baselibrary/utils/baselist.py +32 -32
- re_common/baselibrary/utils/basemotor.py +190 -190
- re_common/baselibrary/utils/basemssql.py +98 -98
- re_common/baselibrary/utils/baseodbc.py +113 -113
- re_common/baselibrary/utils/basepandas.py +302 -302
- re_common/baselibrary/utils/basepeewee.py +11 -11
- re_common/baselibrary/utils/basepika.py +180 -180
- re_common/baselibrary/utils/basepydash.py +143 -143
- re_common/baselibrary/utils/basepymongo.py +230 -230
- re_common/baselibrary/utils/basequeue.py +22 -22
- re_common/baselibrary/utils/baserar.py +57 -57
- re_common/baselibrary/utils/baserequest.py +279 -279
- re_common/baselibrary/utils/baseset.py +8 -8
- re_common/baselibrary/utils/basesmb.py +403 -403
- re_common/baselibrary/utils/basestring.py +382 -382
- re_common/baselibrary/utils/basetime.py +320 -320
- re_common/baselibrary/utils/baseurl.py +121 -121
- re_common/baselibrary/utils/basezip.py +57 -57
- re_common/baselibrary/utils/core/__init__.py +7 -7
- re_common/baselibrary/utils/core/bottomutils.py +18 -18
- re_common/baselibrary/utils/core/mdeprecated.py +327 -327
- re_common/baselibrary/utils/core/mlamada.py +16 -16
- re_common/baselibrary/utils/core/msginfo.py +25 -25
- re_common/baselibrary/utils/core/requests_core.py +103 -103
- re_common/baselibrary/utils/fateadm.py +429 -429
- re_common/baselibrary/utils/importfun.py +123 -123
- re_common/baselibrary/utils/mfaker.py +57 -57
- re_common/baselibrary/utils/my_abc/__init__.py +3 -3
- re_common/baselibrary/utils/my_abc/better_abc.py +32 -32
- re_common/baselibrary/utils/mylogger.py +414 -414
- re_common/baselibrary/utils/myredisclient.py +861 -861
- re_common/baselibrary/utils/pipupgrade.py +21 -21
- re_common/baselibrary/utils/ringlist.py +85 -85
- re_common/baselibrary/utils/version_compare.py +36 -36
- re_common/baselibrary/utils/ydmhttp.py +126 -126
- re_common/facade/lazy_import.py +11 -11
- re_common/facade/loggerfacade.py +25 -25
- re_common/facade/mysqlfacade.py +467 -467
- re_common/facade/now.py +31 -31
- re_common/facade/sqlite3facade.py +257 -257
- re_common/facade/use/mq_use_facade.py +83 -83
- re_common/facade/use/proxy_use_facade.py +19 -19
- re_common/libtest/base_dict_test.py +19 -19
- re_common/libtest/baseavro_test.py +13 -13
- re_common/libtest/basefile_test.py +14 -14
- re_common/libtest/basemssql_test.py +77 -77
- re_common/libtest/baseodbc_test.py +7 -7
- re_common/libtest/basepandas_test.py +38 -38
- re_common/libtest/get_attr_test/get_attr_test_settings.py +14 -14
- re_common/libtest/get_attr_test/settings.py +54 -54
- re_common/libtest/idencode_test.py +53 -53
- re_common/libtest/iniconfig_test.py +35 -35
- re_common/libtest/ip_test.py +34 -34
- re_common/libtest/merge_file_test.py +20 -20
- re_common/libtest/mfaker_test.py +8 -8
- re_common/libtest/mm3_test.py +31 -31
- re_common/libtest/mylogger_test.py +88 -88
- re_common/libtest/myparsel_test.py +27 -27
- re_common/libtest/mysql_test.py +151 -151
- re_common/libtest/pymongo_test.py +21 -21
- re_common/libtest/split_test.py +11 -11
- re_common/libtest/sqlite3_merge_test.py +5 -5
- re_common/libtest/sqlite3_test.py +34 -34
- re_common/libtest/tomlconfig_test.py +30 -30
- re_common/libtest/use_tools_test/__init__.py +2 -2
- re_common/libtest/user/__init__.py +4 -4
- re_common/studio/__init__.py +4 -4
- re_common/studio/assignment_expressions.py +36 -36
- re_common/studio/mydash/test1.py +18 -18
- re_common/studio/pydashstudio/first.py +9 -9
- re_common/studio/streamlitstudio/first_app.py +65 -65
- re_common/studio/streamlitstudio/uber_pickups.py +23 -23
- re_common/studio/test.py +18 -18
- re_common/v2/baselibrary/business_utils/BusinessStringUtil.py +235 -220
- re_common/v2/baselibrary/business_utils/baseencodeid.py +100 -100
- re_common/v2/baselibrary/business_utils/full_doi_path.py +116 -116
- re_common/v2/baselibrary/business_utils/rel_tools.py +6 -6
- re_common/v2/baselibrary/decorators/utils.py +59 -59
- re_common/v2/baselibrary/helpers/search_packge/NearestNeighbors_test.py +105 -105
- re_common/v2/baselibrary/helpers/search_packge/fit_text_match.py +253 -253
- re_common/v2/baselibrary/helpers/search_packge/scikit_learn_text_matcher.py +260 -260
- re_common/v2/baselibrary/helpers/search_packge/test.py +1 -1
- re_common/v2/baselibrary/s3object/baseboto3.py +230 -230
- re_common/v2/baselibrary/tools/WeChatRobot.py +95 -95
- re_common/v2/baselibrary/tools/ac_ahocorasick.py +75 -75
- re_common/v2/baselibrary/tools/concurrency.py +35 -35
- re_common/v2/baselibrary/tools/data_processer/base.py +53 -53
- re_common/v2/baselibrary/tools/data_processer/data_processer.py +497 -508
- re_common/v2/baselibrary/tools/data_processer/data_reader.py +187 -187
- re_common/v2/baselibrary/tools/data_processer/data_writer.py +38 -38
- re_common/v2/baselibrary/tools/dict_tools.py +44 -44
- re_common/v2/baselibrary/tools/dolphinscheduler.py +187 -187
- re_common/v2/baselibrary/tools/hdfs_base_processor.py +204 -204
- re_common/v2/baselibrary/tools/hdfs_bulk_processor.py +67 -67
- re_common/v2/baselibrary/tools/hdfs_data_processer.py +338 -338
- re_common/v2/baselibrary/tools/hdfs_line_processor.py +74 -74
- re_common/v2/baselibrary/tools/list_tools.py +69 -69
- re_common/v2/baselibrary/tools/resume_tracker.py +94 -94
- re_common/v2/baselibrary/tools/search_hash_tools.py +54 -54
- re_common/v2/baselibrary/tools/text_matcher.py +326 -326
- re_common/v2/baselibrary/tools/tree_processor/__init__.py +0 -0
- re_common/v2/baselibrary/tools/tree_processor/builder.py +25 -0
- re_common/v2/baselibrary/tools/tree_processor/node.py +13 -0
- re_common/v2/baselibrary/tools/unionfind_tools.py +60 -60
- re_common/v2/baselibrary/utils/BusinessStringUtil.py +196 -196
- re_common/v2/baselibrary/utils/api_net_utils.py +270 -270
- re_common/v2/baselibrary/utils/author_smi.py +361 -361
- re_common/v2/baselibrary/utils/base_string_similarity.py +158 -158
- re_common/v2/baselibrary/utils/basedict.py +37 -37
- re_common/v2/baselibrary/utils/basehdfs.py +163 -163
- re_common/v2/baselibrary/utils/basepika.py +180 -180
- re_common/v2/baselibrary/utils/basetime.py +94 -77
- re_common/v2/baselibrary/utils/db.py +174 -156
- re_common/v2/baselibrary/utils/elasticsearch.py +46 -0
- re_common/v2/baselibrary/utils/json_cls.py +16 -16
- re_common/v2/baselibrary/utils/mq.py +83 -83
- re_common/v2/baselibrary/utils/n_ary_expression_tree.py +243 -243
- re_common/v2/baselibrary/utils/string_bool.py +187 -186
- re_common/v2/baselibrary/utils/string_clear.py +246 -246
- re_common/v2/baselibrary/utils/string_smi.py +18 -18
- re_common/v2/baselibrary/utils/stringutils.py +312 -271
- re_common/vip/base_step_process.py +11 -11
- re_common/vip/baseencodeid.py +90 -90
- re_common/vip/changetaskname.py +28 -28
- re_common/vip/core_var.py +24 -24
- re_common/vip/mmh3Hash.py +89 -89
- re_common/vip/proxy/allproxys.py +127 -127
- re_common/vip/proxy/allproxys_thread.py +159 -159
- re_common/vip/proxy/cnki_proxy.py +153 -153
- re_common/vip/proxy/kuaidaili.py +87 -87
- re_common/vip/proxy/proxy_all.py +113 -113
- re_common/vip/proxy/update_kuaidaili_0.py +42 -42
- re_common/vip/proxy/wanfang_proxy.py +152 -152
- re_common/vip/proxy/wp_proxy_all.py +181 -181
- re_common/vip/read_rawid_to_txt.py +91 -91
- re_common/vip/title/__init__.py +5 -5
- re_common/vip/title/transform/TransformBookTitleToZt.py +125 -125
- re_common/vip/title/transform/TransformConferenceTitleToZt.py +139 -139
- re_common/vip/title/transform/TransformCstadTitleToZt.py +195 -195
- re_common/vip/title/transform/TransformJournalTitleToZt.py +203 -203
- re_common/vip/title/transform/TransformPatentTitleToZt.py +132 -132
- re_common/vip/title/transform/TransformRegulationTitleToZt.py +114 -114
- re_common/vip/title/transform/TransformStandardTitleToZt.py +135 -135
- re_common/vip/title/transform/TransformThesisTitleToZt.py +135 -135
- re_common/vip/title/transform/__init__.py +10 -10
- {re_common-10.0.39.dist-info → re_common-10.0.41.dist-info}/LICENSE +201 -201
- {re_common-10.0.39.dist-info → re_common-10.0.41.dist-info}/METADATA +16 -16
- re_common-10.0.41.dist-info/RECORD +252 -0
- {re_common-10.0.39.dist-info → re_common-10.0.41.dist-info}/WHEEL +1 -1
- re_common-10.0.39.dist-info/RECORD +0 -248
- {re_common-10.0.39.dist-info → re_common-10.0.41.dist-info}/top_level.txt +0 -0
|
@@ -1,230 +1,230 @@
|
|
|
1
|
-
from typing import List
|
|
2
|
-
|
|
3
|
-
import pymongo
|
|
4
|
-
from pymongo import ReadPreference
|
|
5
|
-
from pymongo.results import InsertOneResult, InsertManyResult
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class BasePyMongo(object):
|
|
9
|
-
|
|
10
|
-
def __init__(self, conn=None, dbname=None):
|
|
11
|
-
self.conn_string = conn
|
|
12
|
-
self.dbname = dbname
|
|
13
|
-
if self.conn_string:
|
|
14
|
-
self.conn()
|
|
15
|
-
|
|
16
|
-
def conn(self):
|
|
17
|
-
"""
|
|
18
|
-
mongodb://cjrw:vipdatacenter@192.168.31.220:27017/
|
|
19
|
-
collection
|
|
20
|
-
:return:
|
|
21
|
-
"""
|
|
22
|
-
self.client = pymongo.MongoClient(self.conn_string)
|
|
23
|
-
|
|
24
|
-
def auth(self, username, password, mechanism='SCRAM-SHA-1'):
|
|
25
|
-
"""
|
|
26
|
-
mongoDB有不同的认证机制,3.0版本以后采用的是'SCRAM-SHA-1', 之前的版本采用的是'MONGODB-CR'。所以,以我的版本情况,显然应该用'MONGODB-CR'
|
|
27
|
-
:param username:
|
|
28
|
-
:param password:
|
|
29
|
-
:param mechanism:
|
|
30
|
-
:return:
|
|
31
|
-
"""
|
|
32
|
-
self.db.authenticate(username, password, mechanism=mechanism)
|
|
33
|
-
|
|
34
|
-
def use_db(self, db=None):
|
|
35
|
-
if db:
|
|
36
|
-
self.db = self.client[db]
|
|
37
|
-
else:
|
|
38
|
-
self.db = self.client[self.dbname]
|
|
39
|
-
|
|
40
|
-
def get_database(self, db, read_preference=ReadPreference.SECONDARY_PREFERRED, **kwargs):
|
|
41
|
-
if db:
|
|
42
|
-
self.db = self.client.get_database(db, read_preference=read_preference, **kwargs)
|
|
43
|
-
else:
|
|
44
|
-
self.db = self.client.get_database(self.dbname, read_preference=read_preference, **kwargs)
|
|
45
|
-
|
|
46
|
-
def show_dbs(self):
|
|
47
|
-
"""
|
|
48
|
-
查询数据库列表
|
|
49
|
-
database_names 在最新版本的 Python 中已废弃,Python3.7+ 之后的版本改为了 list_database_names()。
|
|
50
|
-
:return:
|
|
51
|
-
"""
|
|
52
|
-
dblist = self.client.list_database_names()
|
|
53
|
-
return dblist
|
|
54
|
-
|
|
55
|
-
def create_col(self, colname):
|
|
56
|
-
"""
|
|
57
|
-
在 MongoDB 中,集合只有在内容插入后才会创建! 就是说,创建集合(数据表)后要再插入一个文档(记录),集合才会真正创建。
|
|
58
|
-
创建集合
|
|
59
|
-
:return:
|
|
60
|
-
"""
|
|
61
|
-
self.col = self.db[colname]
|
|
62
|
-
|
|
63
|
-
def get_all_col(self):
|
|
64
|
-
"""
|
|
65
|
-
获取所有集合
|
|
66
|
-
collection_names 在最新版本的 Python 中已废弃,Python3.7+ 之后的版本改为了 list_collection_names()。
|
|
67
|
-
:return:
|
|
68
|
-
"""
|
|
69
|
-
collist = self.db.list_collection_names()
|
|
70
|
-
return collist
|
|
71
|
-
|
|
72
|
-
def insert_one(self, dicts, *args, **kwargs):
|
|
73
|
-
"""
|
|
74
|
-
插入一条数据
|
|
75
|
-
:param dicts:
|
|
76
|
-
:param args:
|
|
77
|
-
:param kwargs:
|
|
78
|
-
:return:
|
|
79
|
-
"""
|
|
80
|
-
return self.col.insert_one(dicts, *args, **kwargs)
|
|
81
|
-
|
|
82
|
-
def replace_one(self, dicts, *args, **kwargs):
|
|
83
|
-
"""
|
|
84
|
-
替换一条数据
|
|
85
|
-
:param dicts:
|
|
86
|
-
:param args:
|
|
87
|
-
:param kwargs:
|
|
88
|
-
:return:
|
|
89
|
-
"""
|
|
90
|
-
return self.col.replace_one(dicts, *args, **kwargs)
|
|
91
|
-
|
|
92
|
-
def get_insert_id(self, insertresult: InsertOneResult):
|
|
93
|
-
"""
|
|
94
|
-
返回_id
|
|
95
|
-
:param insertresult:
|
|
96
|
-
:return:
|
|
97
|
-
"""
|
|
98
|
-
return insertresult.inserted_id
|
|
99
|
-
|
|
100
|
-
def insert_many(self, lists: List[dict], ordered=False, *args, **kwargs):
|
|
101
|
-
"""
|
|
102
|
-
插入多条 直接返回插入的id
|
|
103
|
-
指定id 插入时 dict里面需要包含{"_id":1}这样的格式
|
|
104
|
-
:param lists:
|
|
105
|
-
:param ordered: 如果某一条出现错误 设置为False会继续处理其他数据,默认为true
|
|
106
|
-
,根据测试和说明文档, False后会将list乱序, 乱序后的list, 如果
|
|
107
|
-
没问题的数据在前列, 则会插入, 如果不在前列, 则不会插入 并且返回错误
|
|
108
|
-
, 因此该方法不适合用于 list中的数据 好坏掺杂情况(包括主键冲突)
|
|
109
|
-
:param args:
|
|
110
|
-
:param kwargs:
|
|
111
|
-
:return: InsertManyResult
|
|
112
|
-
"""
|
|
113
|
-
list_result = self.col.insert_many(lists, ordered=False, *args, **kwargs)
|
|
114
|
-
return list_result
|
|
115
|
-
|
|
116
|
-
def get_insert_many_ids(self, list_result: InsertManyResult, *args, **kwargs):
|
|
117
|
-
return list_result.inserted_ids
|
|
118
|
-
|
|
119
|
-
def find_one(self, query=None, filter=None):
|
|
120
|
-
"""
|
|
121
|
-
查询一条
|
|
122
|
-
:return:
|
|
123
|
-
"""
|
|
124
|
-
if query is None:
|
|
125
|
-
query = {}
|
|
126
|
-
return self.col.find_one(query, filter)
|
|
127
|
-
|
|
128
|
-
def find(self, query=None, feild=None, limit=None, **kwargs):
|
|
129
|
-
"""
|
|
130
|
-
kwargs:
|
|
131
|
-
no_cursor_timeout: 设置 no_cursor_timeout=True 解决游标超时问题
|
|
132
|
-
sort: 设置id 升序 sort = [("_id",pymongo.ASCENDING)] # 降序 pymongo.DESCENDING
|
|
133
|
-
|
|
134
|
-
#################################################
|
|
135
|
-
查询所有
|
|
136
|
-
feild = { "_id": 0, "name": 1, "alexa": 1 }
|
|
137
|
-
除了 _id 你不能在一个对象中同时指定 0 和 1,如果你设置了一个字段为 0,则其他都为 1,反之亦然。
|
|
138
|
-
|
|
139
|
-
以下实例除了 alexa 字段外,其他都返回:
|
|
140
|
-
|
|
141
|
-
{ "alexa": 0 }
|
|
142
|
-
以下代码同时指定了 0 和 1 则会报错:
|
|
143
|
-
,{ "name": 1, "alexa": 0 }
|
|
144
|
-
|
|
145
|
-
条件
|
|
146
|
-
{ "name": 1, "alexa": 0 }
|
|
147
|
-
:return: 返回一个pymongo.cursor.Cursor 迭代出结果为dict字典
|
|
148
|
-
"""
|
|
149
|
-
if query is None:
|
|
150
|
-
query = {}
|
|
151
|
-
if feild:
|
|
152
|
-
my_result = self.col.find(query, feild, **kwargs)
|
|
153
|
-
else:
|
|
154
|
-
my_result = self.col.find(query, **kwargs)
|
|
155
|
-
|
|
156
|
-
if limit:
|
|
157
|
-
my_result = my_result.limit(limit)
|
|
158
|
-
|
|
159
|
-
return my_result
|
|
160
|
-
|
|
161
|
-
def update_one(self, query, newvalues):
|
|
162
|
-
"""
|
|
163
|
-
更新一条
|
|
164
|
-
:param query:
|
|
165
|
-
:param newvalues:
|
|
166
|
-
:return:
|
|
167
|
-
"""
|
|
168
|
-
return self.col.update_one(query, newvalues)
|
|
169
|
-
|
|
170
|
-
def update_many(self, query, newvalues):
|
|
171
|
-
"""
|
|
172
|
-
更新多条
|
|
173
|
-
:param query:
|
|
174
|
-
:param newvalues:
|
|
175
|
-
:return:
|
|
176
|
-
"""
|
|
177
|
-
return self.col.update_many(query, newvalues)
|
|
178
|
-
|
|
179
|
-
def sort(self, keys, sorts=-1):
|
|
180
|
-
"""
|
|
181
|
-
查询出来的排序
|
|
182
|
-
:param keys:
|
|
183
|
-
:param sorts:
|
|
184
|
-
:return:
|
|
185
|
-
"""
|
|
186
|
-
return self.col.find().sort(keys, sorts)
|
|
187
|
-
|
|
188
|
-
def delete(self, query):
|
|
189
|
-
"""
|
|
190
|
-
删除一条
|
|
191
|
-
:param query:
|
|
192
|
-
:return:
|
|
193
|
-
"""
|
|
194
|
-
return self.col.delete_one(query)
|
|
195
|
-
|
|
196
|
-
def delete_many(self, query):
|
|
197
|
-
"""
|
|
198
|
-
删除多条
|
|
199
|
-
:param query:
|
|
200
|
-
:return:
|
|
201
|
-
"""
|
|
202
|
-
return self.col.delete_many(query)
|
|
203
|
-
|
|
204
|
-
def delet_all(self):
|
|
205
|
-
"""
|
|
206
|
-
x.deleted_count 删除数
|
|
207
|
-
:return:
|
|
208
|
-
"""
|
|
209
|
-
return self.col.delete_many({})
|
|
210
|
-
|
|
211
|
-
def delete_col(self):
|
|
212
|
-
"""
|
|
213
|
-
删除表
|
|
214
|
-
:return:
|
|
215
|
-
"""
|
|
216
|
-
return self.col.drop()
|
|
217
|
-
|
|
218
|
-
def find_count(self, query=None, feild=None, **kwargs):
|
|
219
|
-
"""
|
|
220
|
-
获取计数
|
|
221
|
-
:return:
|
|
222
|
-
"""
|
|
223
|
-
if query is None:
|
|
224
|
-
query = {}
|
|
225
|
-
if feild:
|
|
226
|
-
my_count = self.col.find(query, feild, **kwargs).count()
|
|
227
|
-
else:
|
|
228
|
-
my_count = self.col.find(query, **kwargs).count()
|
|
229
|
-
|
|
230
|
-
return my_count
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
import pymongo
|
|
4
|
+
from pymongo import ReadPreference
|
|
5
|
+
from pymongo.results import InsertOneResult, InsertManyResult
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BasePyMongo(object):
|
|
9
|
+
|
|
10
|
+
def __init__(self, conn=None, dbname=None):
|
|
11
|
+
self.conn_string = conn
|
|
12
|
+
self.dbname = dbname
|
|
13
|
+
if self.conn_string:
|
|
14
|
+
self.conn()
|
|
15
|
+
|
|
16
|
+
def conn(self):
|
|
17
|
+
"""
|
|
18
|
+
mongodb://cjrw:vipdatacenter@192.168.31.220:27017/
|
|
19
|
+
collection
|
|
20
|
+
:return:
|
|
21
|
+
"""
|
|
22
|
+
self.client = pymongo.MongoClient(self.conn_string)
|
|
23
|
+
|
|
24
|
+
def auth(self, username, password, mechanism='SCRAM-SHA-1'):
|
|
25
|
+
"""
|
|
26
|
+
mongoDB有不同的认证机制,3.0版本以后采用的是'SCRAM-SHA-1', 之前的版本采用的是'MONGODB-CR'。所以,以我的版本情况,显然应该用'MONGODB-CR'
|
|
27
|
+
:param username:
|
|
28
|
+
:param password:
|
|
29
|
+
:param mechanism:
|
|
30
|
+
:return:
|
|
31
|
+
"""
|
|
32
|
+
self.db.authenticate(username, password, mechanism=mechanism)
|
|
33
|
+
|
|
34
|
+
def use_db(self, db=None):
|
|
35
|
+
if db:
|
|
36
|
+
self.db = self.client[db]
|
|
37
|
+
else:
|
|
38
|
+
self.db = self.client[self.dbname]
|
|
39
|
+
|
|
40
|
+
def get_database(self, db, read_preference=ReadPreference.SECONDARY_PREFERRED, **kwargs):
|
|
41
|
+
if db:
|
|
42
|
+
self.db = self.client.get_database(db, read_preference=read_preference, **kwargs)
|
|
43
|
+
else:
|
|
44
|
+
self.db = self.client.get_database(self.dbname, read_preference=read_preference, **kwargs)
|
|
45
|
+
|
|
46
|
+
def show_dbs(self):
|
|
47
|
+
"""
|
|
48
|
+
查询数据库列表
|
|
49
|
+
database_names 在最新版本的 Python 中已废弃,Python3.7+ 之后的版本改为了 list_database_names()。
|
|
50
|
+
:return:
|
|
51
|
+
"""
|
|
52
|
+
dblist = self.client.list_database_names()
|
|
53
|
+
return dblist
|
|
54
|
+
|
|
55
|
+
def create_col(self, colname):
|
|
56
|
+
"""
|
|
57
|
+
在 MongoDB 中,集合只有在内容插入后才会创建! 就是说,创建集合(数据表)后要再插入一个文档(记录),集合才会真正创建。
|
|
58
|
+
创建集合
|
|
59
|
+
:return:
|
|
60
|
+
"""
|
|
61
|
+
self.col = self.db[colname]
|
|
62
|
+
|
|
63
|
+
def get_all_col(self):
|
|
64
|
+
"""
|
|
65
|
+
获取所有集合
|
|
66
|
+
collection_names 在最新版本的 Python 中已废弃,Python3.7+ 之后的版本改为了 list_collection_names()。
|
|
67
|
+
:return:
|
|
68
|
+
"""
|
|
69
|
+
collist = self.db.list_collection_names()
|
|
70
|
+
return collist
|
|
71
|
+
|
|
72
|
+
def insert_one(self, dicts, *args, **kwargs):
|
|
73
|
+
"""
|
|
74
|
+
插入一条数据
|
|
75
|
+
:param dicts:
|
|
76
|
+
:param args:
|
|
77
|
+
:param kwargs:
|
|
78
|
+
:return:
|
|
79
|
+
"""
|
|
80
|
+
return self.col.insert_one(dicts, *args, **kwargs)
|
|
81
|
+
|
|
82
|
+
def replace_one(self, dicts, *args, **kwargs):
|
|
83
|
+
"""
|
|
84
|
+
替换一条数据
|
|
85
|
+
:param dicts:
|
|
86
|
+
:param args:
|
|
87
|
+
:param kwargs:
|
|
88
|
+
:return:
|
|
89
|
+
"""
|
|
90
|
+
return self.col.replace_one(dicts, *args, **kwargs)
|
|
91
|
+
|
|
92
|
+
def get_insert_id(self, insertresult: InsertOneResult):
|
|
93
|
+
"""
|
|
94
|
+
返回_id
|
|
95
|
+
:param insertresult:
|
|
96
|
+
:return:
|
|
97
|
+
"""
|
|
98
|
+
return insertresult.inserted_id
|
|
99
|
+
|
|
100
|
+
def insert_many(self, lists: List[dict], ordered=False, *args, **kwargs):
|
|
101
|
+
"""
|
|
102
|
+
插入多条 直接返回插入的id
|
|
103
|
+
指定id 插入时 dict里面需要包含{"_id":1}这样的格式
|
|
104
|
+
:param lists:
|
|
105
|
+
:param ordered: 如果某一条出现错误 设置为False会继续处理其他数据,默认为true
|
|
106
|
+
,根据测试和说明文档, False后会将list乱序, 乱序后的list, 如果
|
|
107
|
+
没问题的数据在前列, 则会插入, 如果不在前列, 则不会插入 并且返回错误
|
|
108
|
+
, 因此该方法不适合用于 list中的数据 好坏掺杂情况(包括主键冲突)
|
|
109
|
+
:param args:
|
|
110
|
+
:param kwargs:
|
|
111
|
+
:return: InsertManyResult
|
|
112
|
+
"""
|
|
113
|
+
list_result = self.col.insert_many(lists, ordered=False, *args, **kwargs)
|
|
114
|
+
return list_result
|
|
115
|
+
|
|
116
|
+
def get_insert_many_ids(self, list_result: InsertManyResult, *args, **kwargs):
|
|
117
|
+
return list_result.inserted_ids
|
|
118
|
+
|
|
119
|
+
def find_one(self, query=None, filter=None):
|
|
120
|
+
"""
|
|
121
|
+
查询一条
|
|
122
|
+
:return:
|
|
123
|
+
"""
|
|
124
|
+
if query is None:
|
|
125
|
+
query = {}
|
|
126
|
+
return self.col.find_one(query, filter)
|
|
127
|
+
|
|
128
|
+
def find(self, query=None, feild=None, limit=None, **kwargs):
|
|
129
|
+
"""
|
|
130
|
+
kwargs:
|
|
131
|
+
no_cursor_timeout: 设置 no_cursor_timeout=True 解决游标超时问题
|
|
132
|
+
sort: 设置id 升序 sort = [("_id",pymongo.ASCENDING)] # 降序 pymongo.DESCENDING
|
|
133
|
+
|
|
134
|
+
#################################################
|
|
135
|
+
查询所有
|
|
136
|
+
feild = { "_id": 0, "name": 1, "alexa": 1 }
|
|
137
|
+
除了 _id 你不能在一个对象中同时指定 0 和 1,如果你设置了一个字段为 0,则其他都为 1,反之亦然。
|
|
138
|
+
|
|
139
|
+
以下实例除了 alexa 字段外,其他都返回:
|
|
140
|
+
|
|
141
|
+
{ "alexa": 0 }
|
|
142
|
+
以下代码同时指定了 0 和 1 则会报错:
|
|
143
|
+
,{ "name": 1, "alexa": 0 }
|
|
144
|
+
|
|
145
|
+
条件
|
|
146
|
+
{ "name": 1, "alexa": 0 }
|
|
147
|
+
:return: 返回一个pymongo.cursor.Cursor 迭代出结果为dict字典
|
|
148
|
+
"""
|
|
149
|
+
if query is None:
|
|
150
|
+
query = {}
|
|
151
|
+
if feild:
|
|
152
|
+
my_result = self.col.find(query, feild, **kwargs)
|
|
153
|
+
else:
|
|
154
|
+
my_result = self.col.find(query, **kwargs)
|
|
155
|
+
|
|
156
|
+
if limit:
|
|
157
|
+
my_result = my_result.limit(limit)
|
|
158
|
+
|
|
159
|
+
return my_result
|
|
160
|
+
|
|
161
|
+
def update_one(self, query, newvalues):
|
|
162
|
+
"""
|
|
163
|
+
更新一条
|
|
164
|
+
:param query:
|
|
165
|
+
:param newvalues:
|
|
166
|
+
:return:
|
|
167
|
+
"""
|
|
168
|
+
return self.col.update_one(query, newvalues)
|
|
169
|
+
|
|
170
|
+
def update_many(self, query, newvalues):
|
|
171
|
+
"""
|
|
172
|
+
更新多条
|
|
173
|
+
:param query:
|
|
174
|
+
:param newvalues:
|
|
175
|
+
:return:
|
|
176
|
+
"""
|
|
177
|
+
return self.col.update_many(query, newvalues)
|
|
178
|
+
|
|
179
|
+
def sort(self, keys, sorts=-1):
|
|
180
|
+
"""
|
|
181
|
+
查询出来的排序
|
|
182
|
+
:param keys:
|
|
183
|
+
:param sorts:
|
|
184
|
+
:return:
|
|
185
|
+
"""
|
|
186
|
+
return self.col.find().sort(keys, sorts)
|
|
187
|
+
|
|
188
|
+
def delete(self, query):
|
|
189
|
+
"""
|
|
190
|
+
删除一条
|
|
191
|
+
:param query:
|
|
192
|
+
:return:
|
|
193
|
+
"""
|
|
194
|
+
return self.col.delete_one(query)
|
|
195
|
+
|
|
196
|
+
def delete_many(self, query):
|
|
197
|
+
"""
|
|
198
|
+
删除多条
|
|
199
|
+
:param query:
|
|
200
|
+
:return:
|
|
201
|
+
"""
|
|
202
|
+
return self.col.delete_many(query)
|
|
203
|
+
|
|
204
|
+
def delet_all(self):
|
|
205
|
+
"""
|
|
206
|
+
x.deleted_count 删除数
|
|
207
|
+
:return:
|
|
208
|
+
"""
|
|
209
|
+
return self.col.delete_many({})
|
|
210
|
+
|
|
211
|
+
def delete_col(self):
|
|
212
|
+
"""
|
|
213
|
+
删除表
|
|
214
|
+
:return:
|
|
215
|
+
"""
|
|
216
|
+
return self.col.drop()
|
|
217
|
+
|
|
218
|
+
def find_count(self, query=None, feild=None, **kwargs):
|
|
219
|
+
"""
|
|
220
|
+
获取计数
|
|
221
|
+
:return:
|
|
222
|
+
"""
|
|
223
|
+
if query is None:
|
|
224
|
+
query = {}
|
|
225
|
+
if feild:
|
|
226
|
+
my_count = self.col.find(query, feild, **kwargs).count()
|
|
227
|
+
else:
|
|
228
|
+
my_count = self.col.find(query, **kwargs).count()
|
|
229
|
+
|
|
230
|
+
return my_count
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
from queue import Queue
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class BaseQueue(Queue):
|
|
5
|
-
|
|
6
|
-
def __init__(self, num):
|
|
7
|
-
super().__init__(num)
|
|
8
|
-
|
|
9
|
-
def set_size(self, num):
|
|
10
|
-
super().__init__(num)
|
|
11
|
-
|
|
12
|
-
def get_size(self):
|
|
13
|
-
return self.qsize()
|
|
14
|
-
|
|
15
|
-
def is_empty(self):
|
|
16
|
-
return self.empty()
|
|
17
|
-
|
|
18
|
-
# def put(self, item, block=True, timeout=None):
|
|
19
|
-
# self.put(item, block, timeout)
|
|
20
|
-
#
|
|
21
|
-
# def get(self, block=True, timeout=None):
|
|
22
|
-
# self.get(block, timeout)
|
|
1
|
+
from queue import Queue
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BaseQueue(Queue):
|
|
5
|
+
|
|
6
|
+
def __init__(self, num):
|
|
7
|
+
super().__init__(num)
|
|
8
|
+
|
|
9
|
+
def set_size(self, num):
|
|
10
|
+
super().__init__(num)
|
|
11
|
+
|
|
12
|
+
def get_size(self):
|
|
13
|
+
return self.qsize()
|
|
14
|
+
|
|
15
|
+
def is_empty(self):
|
|
16
|
+
return self.empty()
|
|
17
|
+
|
|
18
|
+
# def put(self, item, block=True, timeout=None):
|
|
19
|
+
# self.put(item, block, timeout)
|
|
20
|
+
#
|
|
21
|
+
# def get(self, block=True, timeout=None):
|
|
22
|
+
# self.get(block, timeout)
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import patoolib
|
|
2
|
-
import rarfile as rarfile
|
|
3
|
-
|
|
4
|
-
from re_common.baselibrary.utils.basedir import BaseDir
|
|
5
|
-
from re_common.baselibrary.utils.baseodbc import BaseODBC
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class BaseRAR(object):
|
|
9
|
-
|
|
10
|
-
@classmethod
|
|
11
|
-
def get_rar_file(cls, filepath):
|
|
12
|
-
azip = rarfile.RarFile(filepath)
|
|
13
|
-
return azip
|
|
14
|
-
|
|
15
|
-
@classmethod
|
|
16
|
-
def get_rar_namelist(cls, rar_obj):
|
|
17
|
-
result_list = []
|
|
18
|
-
for f in rar_obj.infolist():
|
|
19
|
-
result_list.append(f.filename)
|
|
20
|
-
|
|
21
|
-
return result_list
|
|
22
|
-
|
|
23
|
-
@classmethod
|
|
24
|
-
def get_file_obj(cls, rar_obj):
|
|
25
|
-
"""
|
|
26
|
-
返回的是一个可迭代对象
|
|
27
|
-
:param rar_obj:
|
|
28
|
-
:return:
|
|
29
|
-
"""
|
|
30
|
-
return rar_obj.infolist()
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
def extractall(cls, rarobj, **kwargs):
|
|
34
|
-
"""
|
|
35
|
-
解压所有文件
|
|
36
|
-
rarfile.RarCannotExec: Cannot find working tool
|
|
37
|
-
C:\Program Files (x86)\WinRAR 加入环境变量 重启pycharm
|
|
38
|
-
但还是有问题
|
|
39
|
-
rarfile.BadRarFile: Failed the read enough data: req=1048576 got=0
|
|
40
|
-
pip install unrar 也无效
|
|
41
|
-
:return:
|
|
42
|
-
"""
|
|
43
|
-
return rarobj.extractall(**kwargs)
|
|
44
|
-
|
|
45
|
-
@classmethod
|
|
46
|
-
def extractall_patoolib(cls, file_path, outdir):
|
|
47
|
-
patoolib.extract_archive(file_path, outdir=outdir)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
# file_path = r'C:\Users\xuzhu\Desktop\VIPPatents_20210618To20210622.rar'
|
|
51
|
-
# rarobj = BaseRAR.get_rar_file(file_path)
|
|
52
|
-
# fileobj = BaseRAR.extractall(rarobj, path=r'C:\Users\xuzhu\Desktop')
|
|
53
|
-
#
|
|
54
|
-
# for file in BaseDir.get_dir_all_files(r"\\192.168.31.184\caiji\cnipr黄斌"):
|
|
55
|
-
# if file.find("VIPPatents_2021") > -1:
|
|
56
|
-
# print(file)
|
|
57
|
-
# BaseRAR.extractall_patoolib(file, outdir=r'\\192.168.31.171\caiji\patent')
|
|
1
|
+
import patoolib
|
|
2
|
+
import rarfile as rarfile
|
|
3
|
+
|
|
4
|
+
from re_common.baselibrary.utils.basedir import BaseDir
|
|
5
|
+
from re_common.baselibrary.utils.baseodbc import BaseODBC
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseRAR(object):
|
|
9
|
+
|
|
10
|
+
@classmethod
|
|
11
|
+
def get_rar_file(cls, filepath):
|
|
12
|
+
azip = rarfile.RarFile(filepath)
|
|
13
|
+
return azip
|
|
14
|
+
|
|
15
|
+
@classmethod
|
|
16
|
+
def get_rar_namelist(cls, rar_obj):
|
|
17
|
+
result_list = []
|
|
18
|
+
for f in rar_obj.infolist():
|
|
19
|
+
result_list.append(f.filename)
|
|
20
|
+
|
|
21
|
+
return result_list
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def get_file_obj(cls, rar_obj):
|
|
25
|
+
"""
|
|
26
|
+
返回的是一个可迭代对象
|
|
27
|
+
:param rar_obj:
|
|
28
|
+
:return:
|
|
29
|
+
"""
|
|
30
|
+
return rar_obj.infolist()
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def extractall(cls, rarobj, **kwargs):
|
|
34
|
+
"""
|
|
35
|
+
解压所有文件
|
|
36
|
+
rarfile.RarCannotExec: Cannot find working tool
|
|
37
|
+
C:\Program Files (x86)\WinRAR 加入环境变量 重启pycharm
|
|
38
|
+
但还是有问题
|
|
39
|
+
rarfile.BadRarFile: Failed the read enough data: req=1048576 got=0
|
|
40
|
+
pip install unrar 也无效
|
|
41
|
+
:return:
|
|
42
|
+
"""
|
|
43
|
+
return rarobj.extractall(**kwargs)
|
|
44
|
+
|
|
45
|
+
@classmethod
|
|
46
|
+
def extractall_patoolib(cls, file_path, outdir):
|
|
47
|
+
patoolib.extract_archive(file_path, outdir=outdir)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# file_path = r'C:\Users\xuzhu\Desktop\VIPPatents_20210618To20210622.rar'
|
|
51
|
+
# rarobj = BaseRAR.get_rar_file(file_path)
|
|
52
|
+
# fileobj = BaseRAR.extractall(rarobj, path=r'C:\Users\xuzhu\Desktop')
|
|
53
|
+
#
|
|
54
|
+
# for file in BaseDir.get_dir_all_files(r"\\192.168.31.184\caiji\cnipr黄斌"):
|
|
55
|
+
# if file.find("VIPPatents_2021") > -1:
|
|
56
|
+
# print(file)
|
|
57
|
+
# BaseRAR.extractall_patoolib(file, outdir=r'\\192.168.31.171\caiji\patent')
|