re-common 0.2.54__py3-none-any.whl → 2.0.1__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/v2/baselibrary/s3object/baseboto3.py +230 -0
- re_common/v2/baselibrary/tools/dict_tools.py +24 -0
- re_common/v2/baselibrary/tools/search_hash_tools.py +33 -0
- re_common/v2/baselibrary/tools/text_matcher.py +223 -0
- re_common/v2/baselibrary/tools/unionfind_tools.py +60 -0
- re_common/v2/baselibrary/utils/BusinessStringUtil.py +74 -0
- re_common/v2/baselibrary/utils/author_smi.py +308 -0
- re_common/v2/baselibrary/utils/basedict.py +26 -0
- re_common/v2/baselibrary/utils/basehdfs.py +127 -0
- re_common/v2/baselibrary/utils/json_cls.py +11 -0
- re_common/v2/baselibrary/utils/string_bool.py +9 -0
- re_common/v2/baselibrary/utils/string_clear.py +98 -0
- re_common/v2/baselibrary/utils/stringutils.py +95 -0
- {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/METADATA +1 -1
- re_common-2.0.1.dist-info/RECORD +25 -0
- re_common/baselibrary/__init__.py +0 -4
- re_common/baselibrary/baseabs/__init__.py +0 -7
- re_common/baselibrary/baseabs/baseabs.py +0 -26
- re_common/baselibrary/database/mbuilder.py +0 -132
- re_common/baselibrary/database/moudle.py +0 -93
- re_common/baselibrary/database/msqlite3.py +0 -194
- re_common/baselibrary/database/mysql.py +0 -169
- re_common/baselibrary/database/sql_factory.py +0 -26
- re_common/baselibrary/mthread/MThreadingRun.py +0 -486
- re_common/baselibrary/mthread/MThreadingRunEvent.py +0 -349
- re_common/baselibrary/mthread/__init__.py +0 -3
- re_common/baselibrary/mthread/mythreading.py +0 -695
- re_common/baselibrary/pakge_other/socks.py +0 -404
- re_common/baselibrary/readconfig/config_factory.py +0 -18
- re_common/baselibrary/readconfig/ini_config.py +0 -317
- re_common/baselibrary/readconfig/toml_config.py +0 -49
- re_common/baselibrary/temporary/envdata.py +0 -36
- re_common/baselibrary/tools/all_requests/aiohttp_request.py +0 -118
- re_common/baselibrary/tools/all_requests/httpx_requet.py +0 -102
- re_common/baselibrary/tools/all_requests/mrequest.py +0 -412
- re_common/baselibrary/tools/all_requests/requests_request.py +0 -81
- re_common/baselibrary/tools/batch_compre/__init__.py +0 -0
- re_common/baselibrary/tools/batch_compre/bijiao_batch.py +0 -31
- re_common/baselibrary/tools/contrast_db3.py +0 -123
- re_common/baselibrary/tools/copy_file.py +0 -39
- re_common/baselibrary/tools/db3_2_sizedb3.py +0 -102
- re_common/baselibrary/tools/foreachgz.py +0 -40
- re_common/baselibrary/tools/get_attr.py +0 -11
- re_common/baselibrary/tools/image_to_pdf.py +0 -62
- re_common/baselibrary/tools/java_code_deal.py +0 -139
- re_common/baselibrary/tools/javacode.py +0 -79
- re_common/baselibrary/tools/mdb_db3.py +0 -48
- re_common/baselibrary/tools/merge_file.py +0 -171
- re_common/baselibrary/tools/merge_gz_file.py +0 -165
- re_common/baselibrary/tools/mhdfstools/__init__.py +0 -0
- re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +0 -42
- re_common/baselibrary/tools/mhdfstools/hdfst.py +0 -42
- re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +0 -38
- re_common/baselibrary/tools/mongo_tools.py +0 -50
- re_common/baselibrary/tools/move_file.py +0 -170
- re_common/baselibrary/tools/move_mongo/__init__.py +0 -0
- re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +0 -63
- re_common/baselibrary/tools/move_mongo/move_mongo_table.py +0 -354
- re_common/baselibrary/tools/move_mongo/use_mttf.py +0 -18
- re_common/baselibrary/tools/move_mongo/use_mv.py +0 -93
- re_common/baselibrary/tools/mpandas/__init__.py +0 -0
- re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +0 -125
- re_common/baselibrary/tools/mpandas/pandas_visualization.py +0 -8
- re_common/baselibrary/tools/myparsel.py +0 -104
- re_common/baselibrary/tools/rename_dir_file.py +0 -37
- re_common/baselibrary/tools/sequoiadb_utils.py +0 -398
- re_common/baselibrary/tools/split_line_to_many.py +0 -25
- re_common/baselibrary/tools/stringtodicts.py +0 -33
- re_common/baselibrary/tools/workwechant_bot.py +0 -84
- re_common/baselibrary/utils/__init__.py +0 -0
- re_common/baselibrary/utils/baseaiohttp.py +0 -296
- re_common/baselibrary/utils/baseaiomysql.py +0 -87
- re_common/baselibrary/utils/baseallstep.py +0 -191
- re_common/baselibrary/utils/baseavro.py +0 -19
- re_common/baselibrary/utils/baseboto3.py +0 -291
- re_common/baselibrary/utils/basecsv.py +0 -32
- re_common/baselibrary/utils/basedict.py +0 -133
- re_common/baselibrary/utils/basedir.py +0 -241
- re_common/baselibrary/utils/baseencode.py +0 -351
- re_common/baselibrary/utils/baseencoding.py +0 -29
- re_common/baselibrary/utils/baseesdsl.py +0 -86
- re_common/baselibrary/utils/baseexcel.py +0 -264
- re_common/baselibrary/utils/baseexcept.py +0 -109
- re_common/baselibrary/utils/basefile.py +0 -654
- re_common/baselibrary/utils/baseftp.py +0 -214
- re_common/baselibrary/utils/basegzip.py +0 -60
- re_common/baselibrary/utils/basehdfs.py +0 -135
- re_common/baselibrary/utils/basehttpx.py +0 -268
- re_common/baselibrary/utils/baseip.py +0 -87
- re_common/baselibrary/utils/basejson.py +0 -2
- re_common/baselibrary/utils/baselist.py +0 -32
- re_common/baselibrary/utils/basemotor.py +0 -190
- re_common/baselibrary/utils/basemssql.py +0 -98
- re_common/baselibrary/utils/baseodbc.py +0 -113
- re_common/baselibrary/utils/basepandas.py +0 -302
- re_common/baselibrary/utils/basepeewee.py +0 -11
- re_common/baselibrary/utils/basepika.py +0 -180
- re_common/baselibrary/utils/basepydash.py +0 -143
- re_common/baselibrary/utils/basepymongo.py +0 -230
- re_common/baselibrary/utils/basequeue.py +0 -22
- re_common/baselibrary/utils/baserar.py +0 -57
- re_common/baselibrary/utils/baserequest.py +0 -279
- re_common/baselibrary/utils/baseset.py +0 -8
- re_common/baselibrary/utils/basesmb.py +0 -403
- re_common/baselibrary/utils/basestring.py +0 -382
- re_common/baselibrary/utils/basetime.py +0 -320
- re_common/baselibrary/utils/basetuple.py +0 -0
- re_common/baselibrary/utils/baseurl.py +0 -121
- re_common/baselibrary/utils/basezip.py +0 -57
- re_common/baselibrary/utils/core/__init__.py +0 -8
- re_common/baselibrary/utils/core/bottomutils.py +0 -18
- re_common/baselibrary/utils/core/mdeprecated.py +0 -327
- re_common/baselibrary/utils/core/mlamada.py +0 -16
- re_common/baselibrary/utils/core/msginfo.py +0 -25
- re_common/baselibrary/utils/core/requests_core.py +0 -103
- re_common/baselibrary/utils/fateadm.py +0 -429
- re_common/baselibrary/utils/importfun.py +0 -123
- re_common/baselibrary/utils/mfaker.py +0 -57
- re_common/baselibrary/utils/my_abc/__init__.py +0 -3
- re_common/baselibrary/utils/my_abc/better_abc.py +0 -32
- re_common/baselibrary/utils/mylogger.py +0 -414
- re_common/baselibrary/utils/myredisclient.py +0 -861
- re_common/baselibrary/utils/pipupgrade.py +0 -21
- re_common/baselibrary/utils/ringlist.py +0 -85
- re_common/baselibrary/utils/version_compare.py +0 -36
- re_common/baselibrary/utils/ydmhttp.py +0 -126
- re_common/facade/__init__.py +0 -1
- re_common/facade/lazy_import.py +0 -11
- re_common/facade/loggerfacade.py +0 -25
- re_common/facade/mysqlfacade.py +0 -467
- re_common/facade/now.py +0 -31
- re_common/facade/sqlite3facade.py +0 -257
- re_common/facade/use/__init__.py +0 -0
- re_common/facade/use/mq_use_facade.py +0 -83
- re_common/facade/use/proxy_use_facade.py +0 -20
- re_common/libtest/__init__.py +0 -0
- re_common/libtest/base_dict_test.py +0 -19
- re_common/libtest/baseavro_test.py +0 -13
- re_common/libtest/basefile_test.py +0 -14
- re_common/libtest/basemssql_test.py +0 -77
- re_common/libtest/baseodbc_test.py +0 -8
- re_common/libtest/basepandas_test.py +0 -38
- re_common/libtest/get_attr_test/__init__.py +0 -0
- re_common/libtest/get_attr_test/get_attr_test_settings.py +0 -14
- re_common/libtest/get_attr_test/settings.py +0 -55
- re_common/libtest/idencode_test.py +0 -54
- re_common/libtest/iniconfig_test.py +0 -35
- re_common/libtest/ip_test.py +0 -35
- re_common/libtest/merge_file_test.py +0 -20
- re_common/libtest/mfaker_test.py +0 -9
- re_common/libtest/mm3_test.py +0 -32
- re_common/libtest/mylogger_test.py +0 -89
- re_common/libtest/myparsel_test.py +0 -28
- re_common/libtest/mysql_test.py +0 -151
- re_common/libtest/pymongo_test.py +0 -21
- re_common/libtest/split_test.py +0 -12
- re_common/libtest/sqlite3_merge_test.py +0 -6
- re_common/libtest/sqlite3_test.py +0 -34
- re_common/libtest/tomlconfig_test.py +0 -30
- re_common/libtest/use_tools_test/__init__.py +0 -3
- re_common/libtest/user/__init__.py +0 -5
- re_common/studio/__init__.py +0 -5
- re_common/studio/assignment_expressions.py +0 -37
- re_common/studio/mydash/__init__.py +0 -0
- re_common/studio/mydash/test1.py +0 -19
- re_common/studio/pydashstudio/__init__.py +0 -0
- re_common/studio/pydashstudio/first.py +0 -9
- re_common/studio/streamlitstudio/__init__.py +0 -0
- re_common/studio/streamlitstudio/first_app.py +0 -66
- re_common/studio/streamlitstudio/uber_pickups.py +0 -24
- re_common/studio/test.py +0 -19
- re_common/vip/__init__.py +0 -0
- re_common/vip/base_step_process.py +0 -11
- re_common/vip/baseencodeid.py +0 -91
- re_common/vip/changetaskname.py +0 -28
- re_common/vip/core_var.py +0 -24
- re_common/vip/mmh3Hash.py +0 -90
- re_common/vip/proxy/__init__.py +0 -0
- re_common/vip/proxy/allproxys.py +0 -127
- re_common/vip/proxy/allproxys_thread.py +0 -159
- re_common/vip/proxy/cnki_proxy.py +0 -153
- re_common/vip/proxy/kuaidaili.py +0 -87
- re_common/vip/proxy/proxy_all.py +0 -113
- re_common/vip/proxy/update_kuaidaili_0.py +0 -42
- re_common/vip/proxy/wanfang_proxy.py +0 -152
- re_common/vip/proxy/wp_proxy_all.py +0 -182
- re_common/vip/read_rawid_to_txt.py +0 -92
- re_common/vip/title/__init__.py +0 -5
- re_common/vip/title/transform/TransformBookTitleToZt.py +0 -125
- re_common/vip/title/transform/TransformConferenceTitleToZt.py +0 -139
- re_common/vip/title/transform/TransformCstadTitleToZt.py +0 -196
- re_common/vip/title/transform/TransformJournalTitleToZt.py +0 -203
- re_common/vip/title/transform/TransformPatentTitleToZt.py +0 -132
- re_common/vip/title/transform/TransformRegulationTitleToZt.py +0 -114
- re_common/vip/title/transform/TransformStandardTitleToZt.py +0 -135
- re_common/vip/title/transform/TransformThesisTitleToZt.py +0 -135
- re_common/vip/title/transform/__init__.py +0 -11
- re_common-0.2.54.dist-info/RECORD +0 -194
- /re_common/{baselibrary/database → v2}/__init__.py +0 -0
- /re_common/{baselibrary/pakge_other → v2/baselibrary}/__init__.py +0 -0
- /re_common/{baselibrary/readconfig → v2/baselibrary/s3object}/__init__.py +0 -0
- /re_common/{baselibrary/temporary → v2/baselibrary/tools}/__init__.py +0 -0
- /re_common/{baselibrary/tools/__init__.py → v2/baselibrary/tools/list_tools.py} +0 -0
- /re_common/{baselibrary/tools/all_requests → v2/baselibrary/utils}/__init__.py +0 -0
- {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/LICENSE +0 -0
- {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/WHEEL +0 -0
- {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/top_level.txt +0 -0
|
@@ -1,87 +0,0 @@
|
|
|
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,32 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,98 +0,0 @@
|
|
|
1
|
-
import pymssql
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class BaseMsSql(object):
|
|
5
|
-
|
|
6
|
-
def __init__(self, host, user, pwd, db, charset, **kwargs):
|
|
7
|
-
"""
|
|
8
|
-
as_dict 作为字典返回
|
|
9
|
-
:param host:
|
|
10
|
-
:param user:
|
|
11
|
-
:param pwd:
|
|
12
|
-
:param db:
|
|
13
|
-
:param kwargs:
|
|
14
|
-
"""
|
|
15
|
-
self.host = host
|
|
16
|
-
self.user = user
|
|
17
|
-
self.pwd = pwd
|
|
18
|
-
self.db = db
|
|
19
|
-
self.charset = charset
|
|
20
|
-
self.kwargs = kwargs
|
|
21
|
-
|
|
22
|
-
def conn(self):
|
|
23
|
-
if not self.db:
|
|
24
|
-
raise (NameError, "没有设置数据库信息")
|
|
25
|
-
self.conn = pymssql.connect(host=self.host,
|
|
26
|
-
user=self.user,
|
|
27
|
-
password=self.pwd,
|
|
28
|
-
database=self.db,
|
|
29
|
-
charset=self.charset,
|
|
30
|
-
**self.kwargs)
|
|
31
|
-
self.cur = self.conn.cursor()
|
|
32
|
-
if not self.cur:
|
|
33
|
-
raise (NameError, "连接数据库失败")
|
|
34
|
-
else:
|
|
35
|
-
return self.cur
|
|
36
|
-
|
|
37
|
-
def exec_select_query(self, sql):
|
|
38
|
-
"""
|
|
39
|
-
执行查询语句
|
|
40
|
-
返回的是一个包含tuple的list,list的元素是记录行,
|
|
41
|
-
tuple的元素是每行记录的字段
|
|
42
|
-
"""
|
|
43
|
-
try:
|
|
44
|
-
self.cur.execute(sql)
|
|
45
|
-
return self.cur
|
|
46
|
-
except:
|
|
47
|
-
self.close()
|
|
48
|
-
|
|
49
|
-
def fetchone(self):
|
|
50
|
-
"""
|
|
51
|
-
获取查询结果的下一行,返回一个元组,或者如果as_dict为True的话
|
|
52
|
-
返回一个字典。如果没有更多可获取的数据了,返回None。
|
|
53
|
-
如果前一个对execute*() 的调用没有产生任何结果集或者还没有提交调用,
|
|
54
|
-
则抛出OperationalError
|
|
55
|
-
:return:
|
|
56
|
-
"""
|
|
57
|
-
return self.cur.fetchone()
|
|
58
|
-
|
|
59
|
-
def fetchmany(self, size=None):
|
|
60
|
-
"""
|
|
61
|
-
获取下一批查询结果,返回一个元组的列表,或者如果as_dict为True的话返回
|
|
62
|
-
一个字典。如果没有更多可获取的数据了,返回一个空列表。
|
|
63
|
-
你可以使用size参数调整之后每一批获取的行数,这个值会一直保留使用。
|
|
64
|
-
如果前一个对execute*() 的调用没有产生任何结果集或者还没有提交调用,
|
|
65
|
-
则抛出OperationalError
|
|
66
|
-
:param size:
|
|
67
|
-
:return:
|
|
68
|
-
"""
|
|
69
|
-
return self.cur.fetchmany(size=size)
|
|
70
|
-
|
|
71
|
-
def fetchall(self):
|
|
72
|
-
"""
|
|
73
|
-
获取查询结果的所有剩余行,返回一个元组的列表,或者如果as_dict为True
|
|
74
|
-
的话返回一个字典。如果没有更多可获取的数据了,返回一个空列表。
|
|
75
|
-
如果前一个对execute*() 的调用没有产生任何结果集或者还没有提交调用,
|
|
76
|
-
则抛出OperationalError
|
|
77
|
-
:return:
|
|
78
|
-
"""
|
|
79
|
-
return self.cur.fetchall()
|
|
80
|
-
|
|
81
|
-
def exec_non_query(self, sql):
|
|
82
|
-
"""
|
|
83
|
-
执行非查询语句
|
|
84
|
-
"""
|
|
85
|
-
try:
|
|
86
|
-
self.cur.execute(sql)
|
|
87
|
-
self.conn.commit()
|
|
88
|
-
return True
|
|
89
|
-
except:
|
|
90
|
-
self.close()
|
|
91
|
-
return False
|
|
92
|
-
|
|
93
|
-
def close(self):
|
|
94
|
-
self.cur.close()
|
|
95
|
-
self.conn.close()
|
|
96
|
-
|
|
97
|
-
def __del__(self):
|
|
98
|
-
self.close()
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import traceback
|
|
3
|
-
|
|
4
|
-
import pypyodbc as pypyodbc
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class BaseODBC(object):
|
|
8
|
-
|
|
9
|
-
def __init__(self, MdbFile):
|
|
10
|
-
self.connStr = r'Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=%s;' % MdbFile
|
|
11
|
-
self.mdbfile = MdbFile
|
|
12
|
-
self.conn = None
|
|
13
|
-
|
|
14
|
-
def conn_mdb(self):
|
|
15
|
-
self.conn = pypyodbc.connect(self.connStr)
|
|
16
|
-
return self
|
|
17
|
-
|
|
18
|
-
def create_mdb(self):
|
|
19
|
-
"""
|
|
20
|
-
创建一个文件,如果存在会保存
|
|
21
|
-
:return:
|
|
22
|
-
"""
|
|
23
|
-
pypyodbc.win_create_mdb(self.mdbfile)
|
|
24
|
-
return self
|
|
25
|
-
|
|
26
|
-
def get_tables(self):
|
|
27
|
-
"""
|
|
28
|
-
获取表名
|
|
29
|
-
:return:
|
|
30
|
-
"""
|
|
31
|
-
# print(self.cur.tables())
|
|
32
|
-
for table in self.cur.tables():
|
|
33
|
-
yield table
|
|
34
|
-
|
|
35
|
-
def get_description(self, sql):
|
|
36
|
-
"""
|
|
37
|
-
获取查询结果的字段信息
|
|
38
|
-
sql = "select * from `journal`"
|
|
39
|
-
:param sql:
|
|
40
|
-
:return:
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
self.cur.execute(sql)
|
|
44
|
-
for row in self.cur.description:
|
|
45
|
-
yield row
|
|
46
|
-
|
|
47
|
-
def select_all(self, sql):
|
|
48
|
-
"""
|
|
49
|
-
查询语句执行
|
|
50
|
-
:param sql:
|
|
51
|
-
:return:
|
|
52
|
-
"""
|
|
53
|
-
self.cur.execute(sql)
|
|
54
|
-
for row in self.cur.fetchall():
|
|
55
|
-
yield row
|
|
56
|
-
|
|
57
|
-
def select_yield(self, sql):
|
|
58
|
-
"""
|
|
59
|
-
查询语句执行
|
|
60
|
-
:param sql:
|
|
61
|
-
:return:
|
|
62
|
-
"""
|
|
63
|
-
for row in self.cur.execute(sql):
|
|
64
|
-
yield row
|
|
65
|
-
|
|
66
|
-
def get_cur(self):
|
|
67
|
-
"""
|
|
68
|
-
获取游标
|
|
69
|
-
:return:
|
|
70
|
-
"""
|
|
71
|
-
self.cur = self.conn.cursor()
|
|
72
|
-
return self.cur
|
|
73
|
-
|
|
74
|
-
def excsql(self, sql, errExit=True):
|
|
75
|
-
"""
|
|
76
|
-
执行sql
|
|
77
|
-
:param sql:
|
|
78
|
-
:param errExit:
|
|
79
|
-
:return:
|
|
80
|
-
"""
|
|
81
|
-
print(sql)
|
|
82
|
-
try:
|
|
83
|
-
self.cur.execute(sql)
|
|
84
|
-
self.conn.commit()
|
|
85
|
-
except:
|
|
86
|
-
print(traceback.format_exc())
|
|
87
|
-
if errExit:
|
|
88
|
-
sys.exit(-1)
|
|
89
|
-
|
|
90
|
-
def exc_list_sql(self, listsql, errExit=True):
|
|
91
|
-
"""
|
|
92
|
-
传入一个sql的列表,循环执行
|
|
93
|
-
:param listsql:
|
|
94
|
-
:param errExit:
|
|
95
|
-
:return:
|
|
96
|
-
"""
|
|
97
|
-
for sql in listsql:
|
|
98
|
-
print('input sql:' + sql)
|
|
99
|
-
try:
|
|
100
|
-
self.cur.execute(sql)
|
|
101
|
-
except:
|
|
102
|
-
print(traceback.format_exc())
|
|
103
|
-
if errExit:
|
|
104
|
-
sys.exit(-1)
|
|
105
|
-
self.conn.commit()
|
|
106
|
-
|
|
107
|
-
def close_all(self):
|
|
108
|
-
"""
|
|
109
|
-
关闭链接
|
|
110
|
-
:return:
|
|
111
|
-
"""
|
|
112
|
-
self.cur.close()
|
|
113
|
-
self.conn.close()
|