re-common 10.0.22__py3-none-any.whl → 10.0.24__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 +195 -0
- re_common/v2/baselibrary/business_utils/__init__.py +0 -0
- re_common/v2/baselibrary/business_utils/rel_tools.py +6 -0
- re_common/v2/baselibrary/decorators/utils.py +59 -59
- re_common/v2/baselibrary/s3object/baseboto3.py +230 -230
- re_common/v2/baselibrary/tools/WeChatRobot.py +95 -79
- re_common/v2/baselibrary/tools/ac_ahocorasick.py +75 -75
- re_common/v2/baselibrary/tools/dict_tools.py +37 -37
- re_common/v2/baselibrary/tools/dolphinscheduler.py +187 -187
- re_common/v2/baselibrary/tools/hdfs_data_processer.py +338 -338
- re_common/v2/baselibrary/tools/list_tools.py +65 -65
- 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/unionfind_tools.py +60 -60
- re_common/v2/baselibrary/utils/BusinessStringUtil.py +196 -196
- re_common/v2/baselibrary/utils/author_smi.py +360 -360
- 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 +161 -161
- re_common/v2/baselibrary/utils/basepika.py +180 -180
- re_common/v2/baselibrary/utils/basetime.py +77 -77
- re_common/v2/baselibrary/utils/db.py +38 -38
- 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 +186 -149
- re_common/v2/baselibrary/utils/string_clear.py +227 -204
- re_common/v2/baselibrary/utils/string_smi.py +18 -18
- re_common/v2/baselibrary/utils/stringutils.py +213 -213
- 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.22.dist-info → re_common-10.0.24.dist-info}/LICENSE +201 -201
- {re_common-10.0.22.dist-info → re_common-10.0.24.dist-info}/METADATA +16 -16
- re_common-10.0.24.dist-info/RECORD +230 -0
- {re_common-10.0.22.dist-info → re_common-10.0.24.dist-info}/WHEEL +1 -1
- re_common-10.0.22.dist-info/RECORD +0 -227
- {re_common-10.0.22.dist-info → re_common-10.0.24.dist-info}/top_level.txt +0 -0
|
@@ -1,87 +1,87 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import socket
|
|
3
|
-
import time
|
|
4
|
-
|
|
5
|
-
import requests
|
|
6
|
-
from re_common.baselibrary.utils.core.mdeprecated import deprecated
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def GetLocalIPByPrefix(prefix):
|
|
10
|
-
"""
|
|
11
|
-
多网卡情况下,根据前缀获取IP
|
|
12
|
-
prefix = "192.168"
|
|
13
|
-
"""
|
|
14
|
-
localIP = ''
|
|
15
|
-
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
|
|
16
|
-
if ip.startswith(prefix):
|
|
17
|
-
localIP = ip
|
|
18
|
-
return localIP
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def get_local_ip(ifname='eth0'):
|
|
22
|
-
"""
|
|
23
|
-
prefix = enp2s0 or eth0
|
|
24
|
-
:param ifname:
|
|
25
|
-
:return:
|
|
26
|
-
"""
|
|
27
|
-
import socket, fcntl, struct
|
|
28
|
-
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
29
|
-
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', bytes(ifname[:15], 'utf-8')))[20:24])
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class BaseIp(object):
|
|
35
|
-
def __init__(self):
|
|
36
|
-
self.ocalIP = ''
|
|
37
|
-
|
|
38
|
-
@deprecated
|
|
39
|
-
def get_ip(self, proxy=None, count=0):
|
|
40
|
-
"""
|
|
41
|
-
获取外网ip
|
|
42
|
-
:return:
|
|
43
|
-
"""
|
|
44
|
-
year = str(time.localtime().tm_year)
|
|
45
|
-
url = "http://" + year + ".ip138.com/ic.asp"
|
|
46
|
-
print(url)
|
|
47
|
-
try:
|
|
48
|
-
response = requests.get(url, proxies=proxy, timeout=(30, 60))
|
|
49
|
-
ip = re.search(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", response.content.decode(errors='ignore')).group(0)
|
|
50
|
-
return ip
|
|
51
|
-
except Exception as e:
|
|
52
|
-
print(str(e))
|
|
53
|
-
count += 1
|
|
54
|
-
if count > 2:
|
|
55
|
-
print("出现 错误请检查url是否因年份发生改变")
|
|
56
|
-
return False
|
|
57
|
-
return self.get_ip(proxy, count)
|
|
58
|
-
|
|
59
|
-
def GetLocalIPByPrefix(self, prefix):
|
|
60
|
-
"""
|
|
61
|
-
# 多网卡情况下,根据前缀获取IP
|
|
62
|
-
:param prefix: 192.168
|
|
63
|
-
:return:
|
|
64
|
-
"""
|
|
65
|
-
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
|
|
66
|
-
if ip.startswith(prefix):
|
|
67
|
-
self.localIP = ip
|
|
68
|
-
return self.localIP
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def work_server(self):
|
|
72
|
-
"""
|
|
73
|
-
开启监测访问本机ip的ip
|
|
74
|
-
:return:
|
|
75
|
-
"""
|
|
76
|
-
|
|
77
|
-
def hello_world_app(environ, start_response):
|
|
78
|
-
status = '200 OK' # HTTP Status
|
|
79
|
-
headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
|
|
80
|
-
start_response(status, headers)
|
|
81
|
-
msg = 'Hello %s\n' % environ["REMOTE_ADDR"]
|
|
82
|
-
return [msg.encode('utf8')]
|
|
83
|
-
|
|
84
|
-
from wsgiref.simple_server import make_server
|
|
85
|
-
with make_server('', 5678, hello_world_app) as httpd:
|
|
86
|
-
print("Serving on port 5678...")
|
|
87
|
-
httpd.serve_forever()
|
|
1
|
+
import re
|
|
2
|
+
import socket
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
from re_common.baselibrary.utils.core.mdeprecated import deprecated
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def GetLocalIPByPrefix(prefix):
|
|
10
|
+
"""
|
|
11
|
+
多网卡情况下,根据前缀获取IP
|
|
12
|
+
prefix = "192.168"
|
|
13
|
+
"""
|
|
14
|
+
localIP = ''
|
|
15
|
+
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
|
|
16
|
+
if ip.startswith(prefix):
|
|
17
|
+
localIP = ip
|
|
18
|
+
return localIP
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_local_ip(ifname='eth0'):
|
|
22
|
+
"""
|
|
23
|
+
prefix = enp2s0 or eth0
|
|
24
|
+
:param ifname:
|
|
25
|
+
:return:
|
|
26
|
+
"""
|
|
27
|
+
import socket, fcntl, struct
|
|
28
|
+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
29
|
+
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', bytes(ifname[:15], 'utf-8')))[20:24])
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class BaseIp(object):
|
|
35
|
+
def __init__(self):
|
|
36
|
+
self.ocalIP = ''
|
|
37
|
+
|
|
38
|
+
@deprecated
|
|
39
|
+
def get_ip(self, proxy=None, count=0):
|
|
40
|
+
"""
|
|
41
|
+
获取外网ip
|
|
42
|
+
:return:
|
|
43
|
+
"""
|
|
44
|
+
year = str(time.localtime().tm_year)
|
|
45
|
+
url = "http://" + year + ".ip138.com/ic.asp"
|
|
46
|
+
print(url)
|
|
47
|
+
try:
|
|
48
|
+
response = requests.get(url, proxies=proxy, timeout=(30, 60))
|
|
49
|
+
ip = re.search(r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", response.content.decode(errors='ignore')).group(0)
|
|
50
|
+
return ip
|
|
51
|
+
except Exception as e:
|
|
52
|
+
print(str(e))
|
|
53
|
+
count += 1
|
|
54
|
+
if count > 2:
|
|
55
|
+
print("出现 错误请检查url是否因年份发生改变")
|
|
56
|
+
return False
|
|
57
|
+
return self.get_ip(proxy, count)
|
|
58
|
+
|
|
59
|
+
def GetLocalIPByPrefix(self, prefix):
|
|
60
|
+
"""
|
|
61
|
+
# 多网卡情况下,根据前缀获取IP
|
|
62
|
+
:param prefix: 192.168
|
|
63
|
+
:return:
|
|
64
|
+
"""
|
|
65
|
+
for ip in socket.gethostbyname_ex(socket.gethostname())[2]:
|
|
66
|
+
if ip.startswith(prefix):
|
|
67
|
+
self.localIP = ip
|
|
68
|
+
return self.localIP
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def work_server(self):
|
|
72
|
+
"""
|
|
73
|
+
开启监测访问本机ip的ip
|
|
74
|
+
:return:
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def hello_world_app(environ, start_response):
|
|
78
|
+
status = '200 OK' # HTTP Status
|
|
79
|
+
headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers
|
|
80
|
+
start_response(status, headers)
|
|
81
|
+
msg = 'Hello %s\n' % environ["REMOTE_ADDR"]
|
|
82
|
+
return [msg.encode('utf8')]
|
|
83
|
+
|
|
84
|
+
from wsgiref.simple_server import make_server
|
|
85
|
+
with make_server('', 5678, hello_world_app) as httpd:
|
|
86
|
+
print("Serving on port 5678...")
|
|
87
|
+
httpd.serve_forever()
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
|
|
2
|
+
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
class BaseList(object):
|
|
2
|
-
|
|
3
|
-
def remove_null(self, lists):
|
|
4
|
-
"""
|
|
5
|
-
清除列表的所有空字符串
|
|
6
|
-
:param lists:
|
|
7
|
-
:return:
|
|
8
|
-
"""
|
|
9
|
-
return [r for r in lists if r != ""]
|
|
10
|
-
|
|
11
|
-
def remove_blank_space(self, lists):
|
|
12
|
-
"""
|
|
13
|
-
清除列表的所有空格数据,有其他字符的不算
|
|
14
|
-
["a"," "," b"], 比如清除中间的 不清除b
|
|
15
|
-
:return:
|
|
16
|
-
"""
|
|
17
|
-
return [r for r in lists if not r.isspace()]
|
|
18
|
-
|
|
19
|
-
def clean_space_first_end(self, lists):
|
|
20
|
-
"""
|
|
21
|
-
清理列表里每个字符串前后的空格
|
|
22
|
-
:param lists:
|
|
23
|
-
:return:
|
|
24
|
-
"""
|
|
25
|
-
return [r.strip() for r in lists]
|
|
26
|
-
|
|
27
|
-
def get_index(self, lists, obj):
|
|
28
|
-
"""
|
|
29
|
-
从列表中找出某个值第一个匹配项的索引位置
|
|
30
|
-
:return:
|
|
31
|
-
"""
|
|
32
|
-
return lists.index(obj)
|
|
1
|
+
class BaseList(object):
|
|
2
|
+
|
|
3
|
+
def remove_null(self, lists):
|
|
4
|
+
"""
|
|
5
|
+
清除列表的所有空字符串
|
|
6
|
+
:param lists:
|
|
7
|
+
:return:
|
|
8
|
+
"""
|
|
9
|
+
return [r for r in lists if r != ""]
|
|
10
|
+
|
|
11
|
+
def remove_blank_space(self, lists):
|
|
12
|
+
"""
|
|
13
|
+
清除列表的所有空格数据,有其他字符的不算
|
|
14
|
+
["a"," "," b"], 比如清除中间的 不清除b
|
|
15
|
+
:return:
|
|
16
|
+
"""
|
|
17
|
+
return [r for r in lists if not r.isspace()]
|
|
18
|
+
|
|
19
|
+
def clean_space_first_end(self, lists):
|
|
20
|
+
"""
|
|
21
|
+
清理列表里每个字符串前后的空格
|
|
22
|
+
:param lists:
|
|
23
|
+
:return:
|
|
24
|
+
"""
|
|
25
|
+
return [r.strip() for r in lists]
|
|
26
|
+
|
|
27
|
+
def get_index(self, lists, obj):
|
|
28
|
+
"""
|
|
29
|
+
从列表中找出某个值第一个匹配项的索引位置
|
|
30
|
+
:return:
|
|
31
|
+
"""
|
|
32
|
+
return lists.index(obj)
|
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from typing import List
|
|
3
|
-
|
|
4
|
-
from motor.motor_asyncio import AsyncIOMotorClient
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class BaseMotor(object):
|
|
8
|
-
|
|
9
|
-
def __init__(self):
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
def AsyncIOMotorClient(self, uri, dbname):
|
|
13
|
-
"""
|
|
14
|
-
异步链接mongo客户端
|
|
15
|
-
:param uri:
|
|
16
|
-
:param dbname:
|
|
17
|
-
:return:
|
|
18
|
-
"""
|
|
19
|
-
self.connection = AsyncIOMotorClient(uri)
|
|
20
|
-
self.db = self.connection[dbname]
|
|
21
|
-
return self
|
|
22
|
-
|
|
23
|
-
def get_col(self, colname):
|
|
24
|
-
"""
|
|
25
|
-
获取表
|
|
26
|
-
:param colname:
|
|
27
|
-
:return:
|
|
28
|
-
"""
|
|
29
|
-
self.col = self.db[colname]
|
|
30
|
-
return self.col
|
|
31
|
-
|
|
32
|
-
async def select_yield(self, query=None):
|
|
33
|
-
"""
|
|
34
|
-
异步查询
|
|
35
|
-
:param query:
|
|
36
|
-
:return:
|
|
37
|
-
"""
|
|
38
|
-
if query is None:
|
|
39
|
-
query = {}
|
|
40
|
-
async for doc in self.col.find(query):
|
|
41
|
-
yield doc
|
|
42
|
-
|
|
43
|
-
async def select(self, query=None):
|
|
44
|
-
"""
|
|
45
|
-
异步查询
|
|
46
|
-
:param query:
|
|
47
|
-
:return:
|
|
48
|
-
"""
|
|
49
|
-
if query is None:
|
|
50
|
-
query = {}
|
|
51
|
-
docs = self.col.find(query)
|
|
52
|
-
lists = await docs.to_list(None)
|
|
53
|
-
return lists
|
|
54
|
-
|
|
55
|
-
async def select_one(self, query=None):
|
|
56
|
-
"""
|
|
57
|
-
异步查询一条
|
|
58
|
-
:param query:
|
|
59
|
-
:return:
|
|
60
|
-
"""
|
|
61
|
-
if query is None:
|
|
62
|
-
query = {}
|
|
63
|
-
doc = await self.col.find_one(query)
|
|
64
|
-
# print(doc)
|
|
65
|
-
return doc
|
|
66
|
-
|
|
67
|
-
async def insert_many(self, lists: List[dict], ordered=False, *args, **kwargs):
|
|
68
|
-
|
|
69
|
-
"""
|
|
70
|
-
插入一个列表(列表内为dict类型)
|
|
71
|
-
:param lists:
|
|
72
|
-
:param ordered: 如果某一条出现错误 设置为False会继续处理其他数据,默认为true
|
|
73
|
-
:param args:
|
|
74
|
-
:param kwargs:
|
|
75
|
-
:return:
|
|
76
|
-
"""
|
|
77
|
-
result = await self.col.insert_many(lists, ordered=ordered, *args, **kwargs)
|
|
78
|
-
# print('inserted %d docs' % (len(result.inserted_ids),))
|
|
79
|
-
return result
|
|
80
|
-
|
|
81
|
-
async def update_one(self, query=None, update=None, upsert=False, *args, **kwargs):
|
|
82
|
-
"""
|
|
83
|
-
|
|
84
|
-
:param query: 样例{"_id" : "1234"},注意巨杉数据库要使用分区键
|
|
85
|
-
:param update: 更新条件 巨杉replace使用update_one {'$replace': {'x': 3}}
|
|
86
|
-
:param upsert:
|
|
87
|
-
:param args:
|
|
88
|
-
:param kwargs:
|
|
89
|
-
:return:
|
|
90
|
-
"""
|
|
91
|
-
result = await self.col.update_one(query, update, upsert, **kwargs)
|
|
92
|
-
# print('matched %d, modified %d' %
|
|
93
|
-
# (result.matched_count, result.modified_count))
|
|
94
|
-
return result
|
|
95
|
-
|
|
96
|
-
async def insert_one(self, dicts):
|
|
97
|
-
"""
|
|
98
|
-
异步插入一条
|
|
99
|
-
:param dicts:
|
|
100
|
-
:return:
|
|
101
|
-
"""
|
|
102
|
-
result = await self.col.insert_one(dicts)
|
|
103
|
-
# print('result %s' % repr(result.inserted_id))
|
|
104
|
-
return result
|
|
105
|
-
|
|
106
|
-
async def replace_one(self, dicts, iddicts=None):
|
|
107
|
-
if iddicts is None:
|
|
108
|
-
iddicts = {"_id": dicts["_id"]}
|
|
109
|
-
result = await self.col.replace_one(iddicts, dicts)
|
|
110
|
-
# print('result %s' % repr(result.modified_count))
|
|
111
|
-
return result
|
|
112
|
-
|
|
113
|
-
async def find(self, doc_hook, query=None, feild=None):
|
|
114
|
-
"""
|
|
115
|
-
异步查询
|
|
116
|
-
for document in await cursor.to_list(length=100):
|
|
117
|
-
"""
|
|
118
|
-
async for doc in self.col.find(query, feild): # 查询所有文档
|
|
119
|
-
await doc_hook(doc)
|
|
120
|
-
|
|
121
|
-
async def update(self, query, sets):
|
|
122
|
-
result = await self.col.update_one(query, {'$set': sets})
|
|
123
|
-
return result
|
|
124
|
-
# print('updated %s document' % result.modified_count)
|
|
125
|
-
|
|
126
|
-
async def run_common(self, doc_hook, commons):
|
|
127
|
-
result = await self.db.command(commons)
|
|
128
|
-
return doc_hook(result)
|
|
129
|
-
|
|
130
|
-
async def delete_many(self, query):
|
|
131
|
-
"""
|
|
132
|
-
|
|
133
|
-
:param query: 一个字典 按照条件删除
|
|
134
|
-
:return:
|
|
135
|
-
"""
|
|
136
|
-
result = await self.col.delete_many(query)
|
|
137
|
-
return result
|
|
138
|
-
|
|
139
|
-
async def delet_one(self, query):
|
|
140
|
-
"""
|
|
141
|
-
删除一条数据
|
|
142
|
-
:param query_id:
|
|
143
|
-
:return:
|
|
144
|
-
"""
|
|
145
|
-
result = await self.col.delete_one(query)
|
|
146
|
-
return result
|
|
147
|
-
|
|
148
|
-
#
|
|
149
|
-
# bs = BaseMotor()
|
|
150
|
-
# bs.AsyncIOMotorClient(
|
|
151
|
-
# "mongodb://192.168.31.26:11817/html_other.justtest?authSource=html_other",
|
|
152
|
-
# "html_other")
|
|
153
|
-
# bs.get_col("justtest")
|
|
154
|
-
#
|
|
155
|
-
# asyncio.get_event_loop().run_until_complete(bs.update_one({"_id" : "1234"},{'$replace': {"_id" : "1235",'x': 4}}))
|
|
156
|
-
#
|
|
157
|
-
# print(bs.select_one({"_id":"Patent_AU19920025315"}))
|
|
158
|
-
#
|
|
159
|
-
# i = 0
|
|
160
|
-
# lists = []
|
|
161
|
-
# start_time = time.time()
|
|
162
|
-
# for file in BaseDir.get_dir_all_files(r"F:\fun2\gz"):
|
|
163
|
-
# print(file)
|
|
164
|
-
# for line in BaseGzip(100).read_gz_file(file):
|
|
165
|
-
# i = i + 1
|
|
166
|
-
# line = line.strip()
|
|
167
|
-
# dicts = json.loads(line)
|
|
168
|
-
# dicts["export_stat"] = 0
|
|
169
|
-
# dicts["_id"] = dicts["rawid"]
|
|
170
|
-
# del dicts["rawid"]
|
|
171
|
-
# lists.append(dicts)
|
|
172
|
-
# if i % 100000 == 1:
|
|
173
|
-
# print(i)
|
|
174
|
-
# try:
|
|
175
|
-
# asyncio.get_event_loop().run_until_complete(bs.insert_many(lists))
|
|
176
|
-
# except BulkWriteError as e:
|
|
177
|
-
# print(e.args)
|
|
178
|
-
# # print(e.details)
|
|
179
|
-
# lists.clear()
|
|
180
|
-
# print(time.time()-start_time)
|
|
181
|
-
#
|
|
182
|
-
# try:
|
|
183
|
-
# asyncio.get_event_loop().run_until_complete(bs.insert_many(lists))
|
|
184
|
-
# except BulkWriteError as e:
|
|
185
|
-
# print(e.args)
|
|
186
|
-
# # print(e.details)
|
|
187
|
-
# lists.clear()
|
|
188
|
-
# print(time.time() - start_time)
|
|
189
|
-
# print(i)
|
|
190
|
-
# asyncio.get_event_loop().run_until_complete(bs.select_one({"_id": "Patent_AU19920025315"}))
|
|
1
|
+
import asyncio
|
|
2
|
+
from typing import List
|
|
3
|
+
|
|
4
|
+
from motor.motor_asyncio import AsyncIOMotorClient
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BaseMotor(object):
|
|
8
|
+
|
|
9
|
+
def __init__(self):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
def AsyncIOMotorClient(self, uri, dbname):
|
|
13
|
+
"""
|
|
14
|
+
异步链接mongo客户端
|
|
15
|
+
:param uri:
|
|
16
|
+
:param dbname:
|
|
17
|
+
:return:
|
|
18
|
+
"""
|
|
19
|
+
self.connection = AsyncIOMotorClient(uri)
|
|
20
|
+
self.db = self.connection[dbname]
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
def get_col(self, colname):
|
|
24
|
+
"""
|
|
25
|
+
获取表
|
|
26
|
+
:param colname:
|
|
27
|
+
:return:
|
|
28
|
+
"""
|
|
29
|
+
self.col = self.db[colname]
|
|
30
|
+
return self.col
|
|
31
|
+
|
|
32
|
+
async def select_yield(self, query=None):
|
|
33
|
+
"""
|
|
34
|
+
异步查询
|
|
35
|
+
:param query:
|
|
36
|
+
:return:
|
|
37
|
+
"""
|
|
38
|
+
if query is None:
|
|
39
|
+
query = {}
|
|
40
|
+
async for doc in self.col.find(query):
|
|
41
|
+
yield doc
|
|
42
|
+
|
|
43
|
+
async def select(self, query=None):
|
|
44
|
+
"""
|
|
45
|
+
异步查询
|
|
46
|
+
:param query:
|
|
47
|
+
:return:
|
|
48
|
+
"""
|
|
49
|
+
if query is None:
|
|
50
|
+
query = {}
|
|
51
|
+
docs = self.col.find(query)
|
|
52
|
+
lists = await docs.to_list(None)
|
|
53
|
+
return lists
|
|
54
|
+
|
|
55
|
+
async def select_one(self, query=None):
|
|
56
|
+
"""
|
|
57
|
+
异步查询一条
|
|
58
|
+
:param query:
|
|
59
|
+
:return:
|
|
60
|
+
"""
|
|
61
|
+
if query is None:
|
|
62
|
+
query = {}
|
|
63
|
+
doc = await self.col.find_one(query)
|
|
64
|
+
# print(doc)
|
|
65
|
+
return doc
|
|
66
|
+
|
|
67
|
+
async def insert_many(self, lists: List[dict], ordered=False, *args, **kwargs):
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
插入一个列表(列表内为dict类型)
|
|
71
|
+
:param lists:
|
|
72
|
+
:param ordered: 如果某一条出现错误 设置为False会继续处理其他数据,默认为true
|
|
73
|
+
:param args:
|
|
74
|
+
:param kwargs:
|
|
75
|
+
:return:
|
|
76
|
+
"""
|
|
77
|
+
result = await self.col.insert_many(lists, ordered=ordered, *args, **kwargs)
|
|
78
|
+
# print('inserted %d docs' % (len(result.inserted_ids),))
|
|
79
|
+
return result
|
|
80
|
+
|
|
81
|
+
async def update_one(self, query=None, update=None, upsert=False, *args, **kwargs):
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
:param query: 样例{"_id" : "1234"},注意巨杉数据库要使用分区键
|
|
85
|
+
:param update: 更新条件 巨杉replace使用update_one {'$replace': {'x': 3}}
|
|
86
|
+
:param upsert:
|
|
87
|
+
:param args:
|
|
88
|
+
:param kwargs:
|
|
89
|
+
:return:
|
|
90
|
+
"""
|
|
91
|
+
result = await self.col.update_one(query, update, upsert, **kwargs)
|
|
92
|
+
# print('matched %d, modified %d' %
|
|
93
|
+
# (result.matched_count, result.modified_count))
|
|
94
|
+
return result
|
|
95
|
+
|
|
96
|
+
async def insert_one(self, dicts):
|
|
97
|
+
"""
|
|
98
|
+
异步插入一条
|
|
99
|
+
:param dicts:
|
|
100
|
+
:return:
|
|
101
|
+
"""
|
|
102
|
+
result = await self.col.insert_one(dicts)
|
|
103
|
+
# print('result %s' % repr(result.inserted_id))
|
|
104
|
+
return result
|
|
105
|
+
|
|
106
|
+
async def replace_one(self, dicts, iddicts=None):
|
|
107
|
+
if iddicts is None:
|
|
108
|
+
iddicts = {"_id": dicts["_id"]}
|
|
109
|
+
result = await self.col.replace_one(iddicts, dicts)
|
|
110
|
+
# print('result %s' % repr(result.modified_count))
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
async def find(self, doc_hook, query=None, feild=None):
|
|
114
|
+
"""
|
|
115
|
+
异步查询
|
|
116
|
+
for document in await cursor.to_list(length=100):
|
|
117
|
+
"""
|
|
118
|
+
async for doc in self.col.find(query, feild): # 查询所有文档
|
|
119
|
+
await doc_hook(doc)
|
|
120
|
+
|
|
121
|
+
async def update(self, query, sets):
|
|
122
|
+
result = await self.col.update_one(query, {'$set': sets})
|
|
123
|
+
return result
|
|
124
|
+
# print('updated %s document' % result.modified_count)
|
|
125
|
+
|
|
126
|
+
async def run_common(self, doc_hook, commons):
|
|
127
|
+
result = await self.db.command(commons)
|
|
128
|
+
return doc_hook(result)
|
|
129
|
+
|
|
130
|
+
async def delete_many(self, query):
|
|
131
|
+
"""
|
|
132
|
+
|
|
133
|
+
:param query: 一个字典 按照条件删除
|
|
134
|
+
:return:
|
|
135
|
+
"""
|
|
136
|
+
result = await self.col.delete_many(query)
|
|
137
|
+
return result
|
|
138
|
+
|
|
139
|
+
async def delet_one(self, query):
|
|
140
|
+
"""
|
|
141
|
+
删除一条数据
|
|
142
|
+
:param query_id:
|
|
143
|
+
:return:
|
|
144
|
+
"""
|
|
145
|
+
result = await self.col.delete_one(query)
|
|
146
|
+
return result
|
|
147
|
+
|
|
148
|
+
#
|
|
149
|
+
# bs = BaseMotor()
|
|
150
|
+
# bs.AsyncIOMotorClient(
|
|
151
|
+
# "mongodb://192.168.31.26:11817/html_other.justtest?authSource=html_other",
|
|
152
|
+
# "html_other")
|
|
153
|
+
# bs.get_col("justtest")
|
|
154
|
+
#
|
|
155
|
+
# asyncio.get_event_loop().run_until_complete(bs.update_one({"_id" : "1234"},{'$replace': {"_id" : "1235",'x': 4}}))
|
|
156
|
+
#
|
|
157
|
+
# print(bs.select_one({"_id":"Patent_AU19920025315"}))
|
|
158
|
+
#
|
|
159
|
+
# i = 0
|
|
160
|
+
# lists = []
|
|
161
|
+
# start_time = time.time()
|
|
162
|
+
# for file in BaseDir.get_dir_all_files(r"F:\fun2\gz"):
|
|
163
|
+
# print(file)
|
|
164
|
+
# for line in BaseGzip(100).read_gz_file(file):
|
|
165
|
+
# i = i + 1
|
|
166
|
+
# line = line.strip()
|
|
167
|
+
# dicts = json.loads(line)
|
|
168
|
+
# dicts["export_stat"] = 0
|
|
169
|
+
# dicts["_id"] = dicts["rawid"]
|
|
170
|
+
# del dicts["rawid"]
|
|
171
|
+
# lists.append(dicts)
|
|
172
|
+
# if i % 100000 == 1:
|
|
173
|
+
# print(i)
|
|
174
|
+
# try:
|
|
175
|
+
# asyncio.get_event_loop().run_until_complete(bs.insert_many(lists))
|
|
176
|
+
# except BulkWriteError as e:
|
|
177
|
+
# print(e.args)
|
|
178
|
+
# # print(e.details)
|
|
179
|
+
# lists.clear()
|
|
180
|
+
# print(time.time()-start_time)
|
|
181
|
+
#
|
|
182
|
+
# try:
|
|
183
|
+
# asyncio.get_event_loop().run_until_complete(bs.insert_many(lists))
|
|
184
|
+
# except BulkWriteError as e:
|
|
185
|
+
# print(e.args)
|
|
186
|
+
# # print(e.details)
|
|
187
|
+
# lists.clear()
|
|
188
|
+
# print(time.time() - start_time)
|
|
189
|
+
# print(i)
|
|
190
|
+
# asyncio.get_event_loop().run_until_complete(bs.select_one({"_id": "Patent_AU19920025315"}))
|