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.
Files changed (207) hide show
  1. re_common/v2/baselibrary/s3object/baseboto3.py +230 -0
  2. re_common/v2/baselibrary/tools/dict_tools.py +24 -0
  3. re_common/v2/baselibrary/tools/search_hash_tools.py +33 -0
  4. re_common/v2/baselibrary/tools/text_matcher.py +223 -0
  5. re_common/v2/baselibrary/tools/unionfind_tools.py +60 -0
  6. re_common/v2/baselibrary/utils/BusinessStringUtil.py +74 -0
  7. re_common/v2/baselibrary/utils/author_smi.py +308 -0
  8. re_common/v2/baselibrary/utils/basedict.py +26 -0
  9. re_common/v2/baselibrary/utils/basehdfs.py +127 -0
  10. re_common/v2/baselibrary/utils/json_cls.py +11 -0
  11. re_common/v2/baselibrary/utils/string_bool.py +9 -0
  12. re_common/v2/baselibrary/utils/string_clear.py +98 -0
  13. re_common/v2/baselibrary/utils/stringutils.py +95 -0
  14. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/METADATA +1 -1
  15. re_common-2.0.1.dist-info/RECORD +25 -0
  16. re_common/baselibrary/__init__.py +0 -4
  17. re_common/baselibrary/baseabs/__init__.py +0 -7
  18. re_common/baselibrary/baseabs/baseabs.py +0 -26
  19. re_common/baselibrary/database/mbuilder.py +0 -132
  20. re_common/baselibrary/database/moudle.py +0 -93
  21. re_common/baselibrary/database/msqlite3.py +0 -194
  22. re_common/baselibrary/database/mysql.py +0 -169
  23. re_common/baselibrary/database/sql_factory.py +0 -26
  24. re_common/baselibrary/mthread/MThreadingRun.py +0 -486
  25. re_common/baselibrary/mthread/MThreadingRunEvent.py +0 -349
  26. re_common/baselibrary/mthread/__init__.py +0 -3
  27. re_common/baselibrary/mthread/mythreading.py +0 -695
  28. re_common/baselibrary/pakge_other/socks.py +0 -404
  29. re_common/baselibrary/readconfig/config_factory.py +0 -18
  30. re_common/baselibrary/readconfig/ini_config.py +0 -317
  31. re_common/baselibrary/readconfig/toml_config.py +0 -49
  32. re_common/baselibrary/temporary/envdata.py +0 -36
  33. re_common/baselibrary/tools/all_requests/aiohttp_request.py +0 -118
  34. re_common/baselibrary/tools/all_requests/httpx_requet.py +0 -102
  35. re_common/baselibrary/tools/all_requests/mrequest.py +0 -412
  36. re_common/baselibrary/tools/all_requests/requests_request.py +0 -81
  37. re_common/baselibrary/tools/batch_compre/__init__.py +0 -0
  38. re_common/baselibrary/tools/batch_compre/bijiao_batch.py +0 -31
  39. re_common/baselibrary/tools/contrast_db3.py +0 -123
  40. re_common/baselibrary/tools/copy_file.py +0 -39
  41. re_common/baselibrary/tools/db3_2_sizedb3.py +0 -102
  42. re_common/baselibrary/tools/foreachgz.py +0 -40
  43. re_common/baselibrary/tools/get_attr.py +0 -11
  44. re_common/baselibrary/tools/image_to_pdf.py +0 -62
  45. re_common/baselibrary/tools/java_code_deal.py +0 -139
  46. re_common/baselibrary/tools/javacode.py +0 -79
  47. re_common/baselibrary/tools/mdb_db3.py +0 -48
  48. re_common/baselibrary/tools/merge_file.py +0 -171
  49. re_common/baselibrary/tools/merge_gz_file.py +0 -165
  50. re_common/baselibrary/tools/mhdfstools/__init__.py +0 -0
  51. re_common/baselibrary/tools/mhdfstools/down_hdfs_files.py +0 -42
  52. re_common/baselibrary/tools/mhdfstools/hdfst.py +0 -42
  53. re_common/baselibrary/tools/mhdfstools/up_hdfs_files.py +0 -38
  54. re_common/baselibrary/tools/mongo_tools.py +0 -50
  55. re_common/baselibrary/tools/move_file.py +0 -170
  56. re_common/baselibrary/tools/move_mongo/__init__.py +0 -0
  57. re_common/baselibrary/tools/move_mongo/mongo_table_to_file.py +0 -63
  58. re_common/baselibrary/tools/move_mongo/move_mongo_table.py +0 -354
  59. re_common/baselibrary/tools/move_mongo/use_mttf.py +0 -18
  60. re_common/baselibrary/tools/move_mongo/use_mv.py +0 -93
  61. re_common/baselibrary/tools/mpandas/__init__.py +0 -0
  62. re_common/baselibrary/tools/mpandas/mpandasreadexcel.py +0 -125
  63. re_common/baselibrary/tools/mpandas/pandas_visualization.py +0 -8
  64. re_common/baselibrary/tools/myparsel.py +0 -104
  65. re_common/baselibrary/tools/rename_dir_file.py +0 -37
  66. re_common/baselibrary/tools/sequoiadb_utils.py +0 -398
  67. re_common/baselibrary/tools/split_line_to_many.py +0 -25
  68. re_common/baselibrary/tools/stringtodicts.py +0 -33
  69. re_common/baselibrary/tools/workwechant_bot.py +0 -84
  70. re_common/baselibrary/utils/__init__.py +0 -0
  71. re_common/baselibrary/utils/baseaiohttp.py +0 -296
  72. re_common/baselibrary/utils/baseaiomysql.py +0 -87
  73. re_common/baselibrary/utils/baseallstep.py +0 -191
  74. re_common/baselibrary/utils/baseavro.py +0 -19
  75. re_common/baselibrary/utils/baseboto3.py +0 -291
  76. re_common/baselibrary/utils/basecsv.py +0 -32
  77. re_common/baselibrary/utils/basedict.py +0 -133
  78. re_common/baselibrary/utils/basedir.py +0 -241
  79. re_common/baselibrary/utils/baseencode.py +0 -351
  80. re_common/baselibrary/utils/baseencoding.py +0 -29
  81. re_common/baselibrary/utils/baseesdsl.py +0 -86
  82. re_common/baselibrary/utils/baseexcel.py +0 -264
  83. re_common/baselibrary/utils/baseexcept.py +0 -109
  84. re_common/baselibrary/utils/basefile.py +0 -654
  85. re_common/baselibrary/utils/baseftp.py +0 -214
  86. re_common/baselibrary/utils/basegzip.py +0 -60
  87. re_common/baselibrary/utils/basehdfs.py +0 -135
  88. re_common/baselibrary/utils/basehttpx.py +0 -268
  89. re_common/baselibrary/utils/baseip.py +0 -87
  90. re_common/baselibrary/utils/basejson.py +0 -2
  91. re_common/baselibrary/utils/baselist.py +0 -32
  92. re_common/baselibrary/utils/basemotor.py +0 -190
  93. re_common/baselibrary/utils/basemssql.py +0 -98
  94. re_common/baselibrary/utils/baseodbc.py +0 -113
  95. re_common/baselibrary/utils/basepandas.py +0 -302
  96. re_common/baselibrary/utils/basepeewee.py +0 -11
  97. re_common/baselibrary/utils/basepika.py +0 -180
  98. re_common/baselibrary/utils/basepydash.py +0 -143
  99. re_common/baselibrary/utils/basepymongo.py +0 -230
  100. re_common/baselibrary/utils/basequeue.py +0 -22
  101. re_common/baselibrary/utils/baserar.py +0 -57
  102. re_common/baselibrary/utils/baserequest.py +0 -279
  103. re_common/baselibrary/utils/baseset.py +0 -8
  104. re_common/baselibrary/utils/basesmb.py +0 -403
  105. re_common/baselibrary/utils/basestring.py +0 -382
  106. re_common/baselibrary/utils/basetime.py +0 -320
  107. re_common/baselibrary/utils/basetuple.py +0 -0
  108. re_common/baselibrary/utils/baseurl.py +0 -121
  109. re_common/baselibrary/utils/basezip.py +0 -57
  110. re_common/baselibrary/utils/core/__init__.py +0 -8
  111. re_common/baselibrary/utils/core/bottomutils.py +0 -18
  112. re_common/baselibrary/utils/core/mdeprecated.py +0 -327
  113. re_common/baselibrary/utils/core/mlamada.py +0 -16
  114. re_common/baselibrary/utils/core/msginfo.py +0 -25
  115. re_common/baselibrary/utils/core/requests_core.py +0 -103
  116. re_common/baselibrary/utils/fateadm.py +0 -429
  117. re_common/baselibrary/utils/importfun.py +0 -123
  118. re_common/baselibrary/utils/mfaker.py +0 -57
  119. re_common/baselibrary/utils/my_abc/__init__.py +0 -3
  120. re_common/baselibrary/utils/my_abc/better_abc.py +0 -32
  121. re_common/baselibrary/utils/mylogger.py +0 -414
  122. re_common/baselibrary/utils/myredisclient.py +0 -861
  123. re_common/baselibrary/utils/pipupgrade.py +0 -21
  124. re_common/baselibrary/utils/ringlist.py +0 -85
  125. re_common/baselibrary/utils/version_compare.py +0 -36
  126. re_common/baselibrary/utils/ydmhttp.py +0 -126
  127. re_common/facade/__init__.py +0 -1
  128. re_common/facade/lazy_import.py +0 -11
  129. re_common/facade/loggerfacade.py +0 -25
  130. re_common/facade/mysqlfacade.py +0 -467
  131. re_common/facade/now.py +0 -31
  132. re_common/facade/sqlite3facade.py +0 -257
  133. re_common/facade/use/__init__.py +0 -0
  134. re_common/facade/use/mq_use_facade.py +0 -83
  135. re_common/facade/use/proxy_use_facade.py +0 -20
  136. re_common/libtest/__init__.py +0 -0
  137. re_common/libtest/base_dict_test.py +0 -19
  138. re_common/libtest/baseavro_test.py +0 -13
  139. re_common/libtest/basefile_test.py +0 -14
  140. re_common/libtest/basemssql_test.py +0 -77
  141. re_common/libtest/baseodbc_test.py +0 -8
  142. re_common/libtest/basepandas_test.py +0 -38
  143. re_common/libtest/get_attr_test/__init__.py +0 -0
  144. re_common/libtest/get_attr_test/get_attr_test_settings.py +0 -14
  145. re_common/libtest/get_attr_test/settings.py +0 -55
  146. re_common/libtest/idencode_test.py +0 -54
  147. re_common/libtest/iniconfig_test.py +0 -35
  148. re_common/libtest/ip_test.py +0 -35
  149. re_common/libtest/merge_file_test.py +0 -20
  150. re_common/libtest/mfaker_test.py +0 -9
  151. re_common/libtest/mm3_test.py +0 -32
  152. re_common/libtest/mylogger_test.py +0 -89
  153. re_common/libtest/myparsel_test.py +0 -28
  154. re_common/libtest/mysql_test.py +0 -151
  155. re_common/libtest/pymongo_test.py +0 -21
  156. re_common/libtest/split_test.py +0 -12
  157. re_common/libtest/sqlite3_merge_test.py +0 -6
  158. re_common/libtest/sqlite3_test.py +0 -34
  159. re_common/libtest/tomlconfig_test.py +0 -30
  160. re_common/libtest/use_tools_test/__init__.py +0 -3
  161. re_common/libtest/user/__init__.py +0 -5
  162. re_common/studio/__init__.py +0 -5
  163. re_common/studio/assignment_expressions.py +0 -37
  164. re_common/studio/mydash/__init__.py +0 -0
  165. re_common/studio/mydash/test1.py +0 -19
  166. re_common/studio/pydashstudio/__init__.py +0 -0
  167. re_common/studio/pydashstudio/first.py +0 -9
  168. re_common/studio/streamlitstudio/__init__.py +0 -0
  169. re_common/studio/streamlitstudio/first_app.py +0 -66
  170. re_common/studio/streamlitstudio/uber_pickups.py +0 -24
  171. re_common/studio/test.py +0 -19
  172. re_common/vip/__init__.py +0 -0
  173. re_common/vip/base_step_process.py +0 -11
  174. re_common/vip/baseencodeid.py +0 -91
  175. re_common/vip/changetaskname.py +0 -28
  176. re_common/vip/core_var.py +0 -24
  177. re_common/vip/mmh3Hash.py +0 -90
  178. re_common/vip/proxy/__init__.py +0 -0
  179. re_common/vip/proxy/allproxys.py +0 -127
  180. re_common/vip/proxy/allproxys_thread.py +0 -159
  181. re_common/vip/proxy/cnki_proxy.py +0 -153
  182. re_common/vip/proxy/kuaidaili.py +0 -87
  183. re_common/vip/proxy/proxy_all.py +0 -113
  184. re_common/vip/proxy/update_kuaidaili_0.py +0 -42
  185. re_common/vip/proxy/wanfang_proxy.py +0 -152
  186. re_common/vip/proxy/wp_proxy_all.py +0 -182
  187. re_common/vip/read_rawid_to_txt.py +0 -92
  188. re_common/vip/title/__init__.py +0 -5
  189. re_common/vip/title/transform/TransformBookTitleToZt.py +0 -125
  190. re_common/vip/title/transform/TransformConferenceTitleToZt.py +0 -139
  191. re_common/vip/title/transform/TransformCstadTitleToZt.py +0 -196
  192. re_common/vip/title/transform/TransformJournalTitleToZt.py +0 -203
  193. re_common/vip/title/transform/TransformPatentTitleToZt.py +0 -132
  194. re_common/vip/title/transform/TransformRegulationTitleToZt.py +0 -114
  195. re_common/vip/title/transform/TransformStandardTitleToZt.py +0 -135
  196. re_common/vip/title/transform/TransformThesisTitleToZt.py +0 -135
  197. re_common/vip/title/transform/__init__.py +0 -11
  198. re_common-0.2.54.dist-info/RECORD +0 -194
  199. /re_common/{baselibrary/database → v2}/__init__.py +0 -0
  200. /re_common/{baselibrary/pakge_other → v2/baselibrary}/__init__.py +0 -0
  201. /re_common/{baselibrary/readconfig → v2/baselibrary/s3object}/__init__.py +0 -0
  202. /re_common/{baselibrary/temporary → v2/baselibrary/tools}/__init__.py +0 -0
  203. /re_common/{baselibrary/tools/__init__.py → v2/baselibrary/tools/list_tools.py} +0 -0
  204. /re_common/{baselibrary/tools/all_requests → v2/baselibrary/utils}/__init__.py +0 -0
  205. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/LICENSE +0 -0
  206. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/WHEEL +0 -0
  207. {re_common-0.2.54.dist-info → re_common-2.0.1.dist-info}/top_level.txt +0 -0
@@ -1,104 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # @Time : 2020/9/16 13:18
3
- # @Author : suhong
4
- # @File : mcss.py
5
- # @Software: PyCharm
6
- import jsonpath as jsonpath
7
- from parsel import Selector
8
-
9
-
10
- class MParsel(object):
11
- def __init__(self, html="", logger=None):
12
- if logger is None:
13
- from re_common.baselibrary import MLogger
14
- logger = MLogger().streamlogger
15
- self.logger = logger
16
- self.html = html
17
- if self.html:
18
- self.set_sel(self.html)
19
-
20
- def set_sel(self, html):
21
- self.html = html
22
- self.sel = Selector(html)
23
-
24
- def css_parsel(self, sel, css_selector={}):
25
- assert self.html, '解析html时html不能为空'
26
- dicts = {}
27
- parent = None
28
- if css_selector:
29
- # 保证 parent 存在时优先解析
30
- if "parent" in css_selector.keys():
31
- parent = sel.css(css_selector["parent"])
32
- for key, value in css_selector.items():
33
- if isinstance(value, dict):
34
- if key == "children":
35
- # assert parent, "parent 不存在"
36
- list_c = []
37
- for p_item in parent:
38
- list_c.append(self.css_parsel(p_item, value))
39
- dicts[key] = list_c
40
- else:
41
- dicts[key] = self.css_parsel(sel, value)
42
- continue
43
- if key == "parent":
44
- continue
45
- dicts[key] = sel.css(value).getall()
46
- return dicts
47
-
48
- def css_parsel_html(self, css_selector={}):
49
- if self.html != "" and css_selector:
50
- dict_ = dict()
51
- for key, value in css_selector.items():
52
- dict_[key] = self.sel.css(value).getall()
53
- return True, dict_
54
- else:
55
- return False, ""
56
-
57
- def xpath_parsel(self, sel, xpath_selector={}):
58
- assert self.html, '解析html时html不能为空'
59
- dicts = {}
60
- parent = None
61
- if xpath_selector:
62
- # 保证 parent 存在时优先解析
63
- if "parent" in xpath_selector.keys():
64
- parent = sel.xpath(xpath_selector["parent"])
65
- for key, value in xpath_selector.items():
66
- if isinstance(value, dict):
67
- if key == "children":
68
- # assert parent, "parent 不存在"
69
- list_c = []
70
- for p_item in parent:
71
- list_c.append(self.xpath_parsel(p_item, value))
72
- dicts[key] = list_c
73
- else:
74
- dicts[key] = self.xpath_parsel(sel, value)
75
- continue
76
- if key == "parent":
77
- continue
78
- dicts[key] = sel.xpath(value).getall()
79
- return dicts
80
-
81
- def xpath_parsel_html(self, html="", xpath_selector={}):
82
- if html != "" and xpath_selector:
83
- sel = Selector(html)
84
- dict_ = dict()
85
- for key, value in xpath_selector.items():
86
- dict_[key] = sel.xpath(value).getall()
87
- return True, dict_
88
- else:
89
- return False, ""
90
-
91
- def json_parsel(self, sel_json, json_selector={}):
92
- assert self.html, '解析html时html不能为空'
93
- re_dict = {}
94
- if json_selector:
95
- for key, value in json_selector.items():
96
- re_dict[key] = jsonpath(sel_json, value)
97
- dicts = {
98
- "json_raw":sel_json,
99
- "data":re_dict
100
- }
101
- return dicts
102
-
103
- def asd(self):
104
- pass
@@ -1,37 +0,0 @@
1
- """
2
- 重命名目录下的文件
3
- """
4
- from re_common.baselibrary.utils.basedir import BaseDir
5
- from re_common.baselibrary.utils.basefile import BaseFile
6
-
7
-
8
- def get_next_suffix(num):
9
- num = num + 1
10
- return "_" + str(num).zfill(4)
11
-
12
-
13
- def rename_db3(dirpath, rename, start=0):
14
- """
15
- 重命名db3 文件 以后缀_001 或者 _000 开始
16
- :param rename:
17
- :param start: 1 代表_001 0代表_000
18
- :return:
19
- """
20
- """
21
-
22
- :param dirpath:
23
- :param rename:
24
- :param start:
25
- :return:
26
- """
27
-
28
- for file in BaseDir.get_dir_all_files(dirpath):
29
- if file.endswith(".db3"):
30
- BaseDir.get_upper_dir(file, -1)
31
- renamepath = BaseFile.get_new_path(dirpath, rename + get_next_suffix(start) + ".db3")
32
- BaseFile.rename_file(file, renamepath)
33
- start = start + 1
34
-
35
-
36
- rename_db3(r"\\192.168.31.65\d$\zt_data_db3\zt_normal_grx\zt_cnki_qk_20200323", "zt_cnki_qk_20200323")
37
- rename_db3(r"\\192.168.31.65\d$\zt_data_db3\zt_normal_grx\zt_wf_qk_20200323", "zt_wf_qk_20200323")
@@ -1,398 +0,0 @@
1
- from typing import Union
2
-
3
- from pysequoiadb import client
4
- from pysequoiadb.collection import INSERT_FLG_DEFAULT
5
- from pysequoiadb.lob import LOB_READ, LOB_WRITE
6
-
7
-
8
- class SequoiadbUtils(object):
9
-
10
- def __init__(self):
11
- self.db_data = None
12
- self.db = None
13
- self.cs = None
14
- self.cl = None
15
- self.list_hosts = None
16
-
17
- def set_db_data(self, db_data: dict):
18
- self.db_data = db_data
19
- return self
20
-
21
- def set_list_hosts(self, list_hosts):
22
- self.list_hosts = list_hosts
23
- return self
24
-
25
- def build(self):
26
- self.link_db()
27
- self.link_col()
28
- return self
29
-
30
- def set_cl(self, cl):
31
- self.cl = cl
32
-
33
- def link_db(self):
34
- """
35
- 初始化 host, port, user, password ,连接
36
- """
37
- host = self.db_data.get("host", "")
38
- port = self.db_data.get("port", "")
39
- user = self.db_data.get("user", "")
40
- password = self.db_data.get("password", "")
41
- try:
42
- self.db = client(host=host, service=port, user=user, psw=password)
43
- if self.list_hosts:
44
- # self.list_hosts = [
45
- # {'host': '192.168.31.21', 'service': '11810'},
46
- # {'host': '192.168.31.22', 'service': '11810'},
47
- # {'host': '192.168.31.23', 'service': '11810'},
48
- # {'host': '192.168.31.24', 'service': '11810'},
49
- # {'host': '192.168.31.25', 'service': '11810'},
50
- # {'host': '192.168.31.26', 'service': '11810'},
51
- # {'host': '192.168.31.27', 'service': '11810'},
52
- # {'host': '192.168.31.219', 'service': '11810'},
53
- # {'host': '192.168.31.208', 'service': '11810'}
54
- # ]
55
- self.db.connect_to_hosts(self.list_hosts, user=user, psw=password)
56
- return self.db
57
- except Exception as e:
58
- raise e
59
-
60
- def link_col(self):
61
- collection_space_name = self.db_data.get("collection_space_name", "")
62
- collection_name = self.db_data.get("collection_name", "")
63
- is_create = self.db_data.get("is_create", "false")
64
- try:
65
- self.cl = self.db.get_collection("{}.{}".format(collection_space_name, collection_name))
66
- return self.cl
67
- except:
68
- print('集合空间或者集合不存在')
69
- if is_create == "true":
70
- try:
71
- self.cs = self.db.create_collection_space(collection_space_name)
72
- print('创建集合空间 ', collection_space_name)
73
- except:
74
- self.cs = self.db.get_collection_space(collection_space_name)
75
- try:
76
- self.cl = self.cs.create_collection(collection_name)
77
- print('创建集合空间 ', collection_name)
78
- return self.cl
79
- except:
80
- self.cl = self.cs.get_collection(collection_name)
81
-
82
- def insert(self, record: dict, cl=None):
83
- """
84
- 插入数据
85
- :return A ObjectId object of record inserted. eg: { '_id': ObjectId('5d5149ade3071dce3692e93b') }
86
- """
87
- if cl is None:
88
- cl = self.cl
89
- return cl.insert(record)
90
-
91
- def replace_one(self, doc, cl=None, **kwargs):
92
- """
93
- 更新数据
94
- rule: 更新数据
95
- kwargs:
96
- condition: 匹配规则
97
- hint: https://doc.sequoiadb.com/cn/SequoiaDB-cat_id-1432190835-edition_id-300
98
- flags: 默认为0 UPDATE_FLG_KEEP_SHARDINGKEY 更新规则中的分片键在执行时没有被过滤更新或插入。
99
- 如果不给flags,不保留更新规则中的分区键字段,只更新非分区键字段。否则 保留更新规则中的分区键字段。
100
- 指定 flags 参数:保留更新规则中的分区键字段。因为目前不支持更新分区键,所以会报错。
101
- """
102
- if cl is None:
103
- cl = self.cl
104
- rule = {"$replace": doc}
105
- return cl.update(rule, **kwargs)
106
-
107
- def bulk_insert(self, flag: int, records: Union[list, tuple], cl=None):
108
- """
109
- 插入多条数据
110
- :param flag:
111
- INSERT_FLG_DEFAULT : 当设置INSERT_FLG_DEFAULT时,当记录命中索引时,数据库将停止插入键重复错误。,插入正常也不会返回id
112
- INSERT_FLG_CONTONDUP : 如果记录命中索引键重复错误,数据库将跳过它
113
- INSERT_FLG_RETURN_OID : 返回记录中“_id”字段的值。,如果有重复会报错
114
- INSERT_FLG_REPLACEONDUP : 如果记录命中索引键重复错误,数据库将用插入新记录,然后继续插入。
115
- :param records:
116
- :return:
117
- 当flag不等于INSERT_FLG_RETURN_OID时,将返回一个空字典, eg: { }.
118
- eg: { '_id': [ObjectId('5d514a25c764c60acb58de38'), ObjectId('5d514a25c764c60acb58de39')]}
119
- """
120
- if cl is None:
121
- cl = self.cl
122
- return cl.bulk_insert(flag, records)
123
-
124
- def insert_with_flag(self, record, flag=INSERT_FLG_DEFAULT, cl=None):
125
- """
126
- 插入数据,并可以选择flags
127
- 和 bulk_insert 一样的标志,这样可以实现replace
128
- :param record:
129
- :param flag:
130
- :return:
131
- """
132
- if cl is None:
133
- cl = self.cl
134
- return cl.insert_with_flag(record, flag)
135
-
136
- def delete(self, cl=None, **kwargs):
137
- """
138
- 删除数据
139
- condition: 匹配规则后,删除文档,如果没有提供,删除所有文档
140
- 在 https://doc.sequoiadb.com/cn/sequoiadb-cat_id-1432190843-edition_id-300对hint
141
- hint: 指定访问计划(v3.0后意义不大)
142
- """
143
- if cl is None:
144
- cl = self.cl
145
- return cl.delete(**kwargs)
146
-
147
- def update(self, rule: dict, cl=None, **kwargs):
148
- """
149
- 更新数据
150
- rule: 更新数据
151
- kwargs:
152
- condition: 匹配规则
153
- hint: https://doc.sequoiadb.com/cn/SequoiaDB-cat_id-1432190835-edition_id-300
154
- flags: 默认为0 UPDATE_FLG_KEEP_SHARDINGKEY 更新规则中的分片键在执行时没有被过滤更新或插入。
155
- 如果不给flags,不保留更新规则中的分区键字段,只更新非分区键字段。否则 保留更新规则中的分区键字段。
156
- 指定 flags 参数:保留更新规则中的分区键字段。因为目前不支持更新分区键,所以会报错。
157
- """
158
- if cl is None:
159
- cl = self.cl
160
- return cl.update(rule, **kwargs)
161
-
162
- def upsert(self, rule, cl=None, **kwargs):
163
- """
164
- 该函数用于更新集合记录。upsert 方法跟 update 方法都是对记录进行更新,不同的是当使用 cond 参数在集合中匹配不到记录时,update 不做任何操作,而 upsert 方法会做一次插入操作
165
- https://doc.sequoiadb.com/cn/sequoiadb-cat_id-1432190848-edition_id-500
166
- :param rule: 更新规则
167
- :param kwargs: condition: 条件
168
- hint: 指定索引
169
- setOnInsert: 在做插入操作时向插入的记录中追加字段。
170
- flags:UPDATE_FLG_KEEP_SHARDINGKEY 默认不给
171
- :return:
172
- """
173
- if cl is None:
174
- cl = self.cl
175
- cl.upsert(rule, **kwargs)
176
-
177
- def query(
178
- self,
179
- condition: dict = None,
180
- selector: dict = None,
181
- order_by: dict = None,
182
- hint: dict = None,
183
- num_to_skip: int = 0,
184
- num_to_return: int = -1,
185
- flags: int = 0,
186
- cl=None):
187
- """
188
- https://doc.sequoiadb.com/cn/sequoiadb-cat_id-1552489127-edition_id-500
189
- 查询数据
190
- condition:为空时,查询所有记录;不为空时,查询符合条件记录。如:{"age":{"$gt":30}}。关于匹配条件的使用,可参考匹配符
191
- selector:为空时,返回记录的所有字段;如果指定的字段名记录中不存在,则按用户设定的内容原样返回。如:{"name":"","age":"","addr":""}。字段值为空字符串即可,数据库只关心字段名。关于选择条件的使用,可参考选择符。
192
- order_by:指定结果集按指定字段名排序的情况。字段名的值为1或者-1,如:{"name":1,"age":-1}。1代表升序;-1代表降序。 如果不设定 sort 则表示不对结果集做排序。
193
- hint:指定查询使用索引的情况。字段名可以为任意不重复的字符串,数据库只关心字段值。
194
- num_to_skip:自定义从结果集哪条记录开始返回。默认值为0,表示从第一条记录开始返回。
195
- num_to_return:自定义返回结果集的记录条数。默认值为-1,表示返回从skipNum位置开始到结果集结束位置的所有记录。
196
- flags: QUERY_FLG_WITH_RETURNDATA:强制使用指定的提示进行查询,如果数据库没有提示分配的索引,则查询失败
197
- query_flg_parallelall:启用并行子查询,每个子查询将完成扫描数据的不同部分
198
- QUERY_FLG_FORCE_HINT:一般情况下,直到游标从数据库获取数据,查询才会返回数据,当添加此标志时,在查询响应中返回数据,将会更加高性能
199
- QUERY_PREPARE_MORE:启用查询时准备更多数据
200
- QUERY_FLG_FOR_UPDATE:当事务被打开且事务隔离级别为“RC”时,事务锁将不会在事务提交或回滚之前释放。
201
- """
202
- if condition is None:
203
- condition = {}
204
- if selector is None:
205
- selector = {}
206
- if order_by is None:
207
- order_by = {}
208
- if hint is None:
209
- hint = {}
210
- if cl is None:
211
- cl = self.cl
212
- return cl.query(condition=condition,
213
- selector=selector,
214
- order_by=order_by,
215
- hint=hint,
216
- num_to_skip=num_to_skip,
217
- num_to_return=num_to_return,
218
- flags=flags)
219
- # data_list = list()
220
- # while 1:
221
- # try:
222
- # result = results.next()
223
- # data_list.append(result)
224
- # except:
225
- # break
226
- # return str(data_list)
227
-
228
- def query_and_update(self, update, cl=None, **kwargs):
229
- """
230
-
231
- :param update: 更新的规则
232
- :param kwargs: 查询条件,和上面查询一样多一个参数
233
- return_new bool 当为True时,返回更新后的文档,而不是原始文档
234
- :return: 返回查询的结果
235
- """
236
- if cl is None:
237
- cl = self.cl
238
- return cl.query_and_update(update, **kwargs)
239
-
240
- def query_and_remove(self, cl=None, **kwargs):
241
- """
242
- 查询删除
243
- 条件和查询完全一样
244
- :param kwargs:
245
- :return: 返回查询的结果
246
- """
247
- if cl is None:
248
- cl = self.cl
249
- return cl.query_and_remove(**kwargs)
250
-
251
- def save(self, doc, cl=None):
252
- """
253
- 存在更新,不存在插入
254
- :param doc:
255
- :return:
256
- """
257
- if cl is None:
258
- cl = self.cl
259
- return cl.save(doc)
260
-
261
- def create_lob(self, oid=None, cl=None):
262
- """
263
- 相当于一个空间
264
- :param oid: bson.ObjectId 指定要创建的lob的oid,如果为None,则自动生成oid
265
- :return: 一个objectid
266
- """
267
- if cl is None:
268
- cl = self.cl
269
- return cl.create_lob(oid=oid)
270
-
271
- def create_lob_id(self, timestamp=None, cl=None):
272
- """
273
- 创建lob id
274
- :param timestamp: 用于于生成lob id,如果为None则由服务器生成时间戳。
275
- 格式:YYYY-MM-DD-HH.mm.ss。如:“2019-07-23 18.04.07”
276
- :return: lob的一个ObjectId对象。
277
- """
278
- if cl is None:
279
- cl = self.cl
280
- return cl.create_lob_id(timestamp=timestamp)
281
-
282
- def open_lob(self, oid, mode=LOB_READ, cl=None):
283
- """
284
- 打开指定的lob进行读写
285
- :param oid: str/bson.ObjectId 指定的oid
286
- :param mode:
287
- int The open mode:
288
- lob.LOB_READ for reading.
289
- lob.LOB_WRITE for writing.
290
- lob.LOB_SHARE_READ for share reading.
291
- lob.LOB_SHARE_READ | lob.LOB_WRITE for both reading and writing.
292
-
293
- :return: a lob object
294
- """
295
- if cl is None:
296
- cl = self.cl
297
- return cl.open_lob(oid, mode)
298
-
299
- def get_lob(self, oid, cl=None):
300
- """
301
- 获取指定的lob
302
- :param oid: str/bson.ObjectId The specified oid
303
- :return: a lob object
304
- """
305
- if cl is None:
306
- cl = self.cl
307
- return cl.get_lob(oid)
308
-
309
- def remove_lob(self, oid, cl=None):
310
- """
311
- 删除lob
312
- :param oid: str/bson.ObjectId The oid of the lob to be remove.
313
- :return:
314
- """
315
- if cl is None:
316
- cl = self.cl
317
- cl.remove_lob(oid)
318
-
319
- def truncate_lob(self, oid, length, cl=None):
320
- """截断lob
321
-
322
- Parameters:
323
- Name Type Info:
324
- oid str/bson.ObjectId The oid of the lob to be truncated.
325
- length int/long The truncate length
326
- Exceptions:
327
- pysequoiadb.error.SDBBaseError
328
- """
329
- if cl is None:
330
- cl = self.cl
331
- cl.truncate_lob(oid, length)
332
-
333
- def list_lobs(self, cl=None, **kwargs):
334
- """
335
- lob 列表
336
- :param kwargs:
337
- Name Type Info:
338
- - condition dict The matching rule, return all the lob if not provided.
339
- - selected dict The selective rule, return the whole infomation if not provided.
340
- - order_by dict The ordered rule, result set is unordered if not provided.
341
- - hint dict Specified options. eg. {"ListPieces": 1} means get the detail piece info of lobs.
342
- - num_to_skip long Skip the first numToSkip lob, default is 0.
343
- - num_to_Return long Only return numToReturn lob, default is -1 for returning all results.
344
-
345
- :return: a cursor object of query
346
- """
347
- if cl is None:
348
- cl = self.cl
349
- return cl.list_lobs(**kwargs)
350
-
351
- def lob_insert(self, record: str, cl=None):
352
- """
353
- 插入lob数据,输入字符串
354
- """
355
- if cl is None:
356
- cl = self.cl
357
- try:
358
- lob_oid = cl.create_lob_id()
359
- lob_obj = cl.create_lob(lob_oid)
360
- lob_obj.write(record, len(record))
361
- lob_obj.close()
362
- return str(lob_oid)
363
- except Exception as e:
364
- raise e
365
-
366
- def replace_lob(self, record: str, lob_oid: str, cl=None):
367
- """
368
- 插入lob数据,输入字符串
369
- """
370
- if cl is None:
371
- cl = self.cl
372
- try:
373
- lob_obj = cl.open_lob(lob_oid, mode=LOB_WRITE)
374
- lob_obj.write(record, len(record))
375
- lob_obj.close()
376
- return str(lob_oid)
377
- except Exception as e:
378
- raise e
379
-
380
- def lob_insert_for_file(self, filepath: str):
381
- pass
382
-
383
- def lob_query(self, oid, cl=None):
384
- """
385
- 查询lob数据
386
- """
387
- if cl is None:
388
- cl = self.cl
389
- lob_file = cl.open_lob(oid)
390
- return str(lob_file.read(lob_file.get_size()), encoding='utf-8')
391
-
392
- def close(self):
393
- self.db.disconnect()
394
-
395
-
396
- def get_col(sdb_util: SequoiadbUtils, collection_space_name, collection_name):
397
- cl = sdb_util.db.get_collection("{}.{}".format(collection_space_name, collection_name))
398
- return cl
@@ -1,25 +0,0 @@
1
- """
2
- 一行文本按指定符号分割为多行文本
3
- """
4
-
5
-
6
- class Split_2_lines(object):
7
- def __int__(self):
8
- pass
9
-
10
- def split_line(self, infilepath, sign, outfilepath=None):
11
- """
12
- :param infilepath: 输入文件位置
13
- :param sign: 分割符号
14
- :param outfilepath: 输出文件位置
15
- :return:
16
- """
17
- with open(infilepath, 'r', encoding='utf-8')as f:
18
- for line in f:
19
- list_ = line.split(sign)[:-1]
20
- for num in list_:
21
- new_line = num + sign + "\n"
22
- with open(outfilepath, 'a', encoding='utf-8')as fw:
23
- fw.write(new_line)
24
- print(new_line)
25
- print("输出{}成功".format(outfilepath))
@@ -1,33 +0,0 @@
1
- from re_common.baselibrary.utils.baselist import BaseList
2
-
3
-
4
- class StringToDicts(object):
5
-
6
- def __init__(self):
7
- pass
8
-
9
- def string_to_dicts_by_equal(self, strings):
10
- """
11
- 将string 按行分组 然后每组内使用等号分割 前面为字典的键 后面为字典的值
12
- strings = ```
13
- host = 192.168.31.209
14
- user = root
15
- passwd = vipdatacenter
16
- db = data_gather_record
17
- port = 3306
18
- chartset = utf8
19
- ```
20
- :param strings:
21
- :return:
22
- """
23
- baselistobj = BaseList()
24
- lists = strings.split("\n")
25
- lists = baselistobj.remove_null(lists)
26
- lists = baselistobj.remove_blank_space(lists)
27
- lists = baselistobj.clean_space_first_end(lists)
28
- dicts = {}
29
- for item in lists:
30
- key = item.split("=")[0].strip()
31
- values = item.split("=")[1].strip()
32
- dicts[key] = values
33
- return dicts
@@ -1,84 +0,0 @@
1
- import json
2
-
3
- import requests
4
-
5
- from re_common.baselibrary.utils.baserequest import BaseRequest
6
-
7
-
8
- class WorkWechatBot(object):
9
-
10
- def __init__(self,key):
11
- super().__init__()
12
- self.bsrequest = BaseRequest()
13
- self.upurl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key={}&type=file".format(key)
14
- self.url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key={}".format(key)
15
-
16
- def sendMsg(self, data):
17
- headers = {"Content-Type": "application/json"}
18
- BoolResult, errString, r = self.bsrequest.base_request_post(self.url,
19
- headers=headers,
20
- data=data,
21
- timeout=(10, 30)
22
- )
23
- if BoolResult:
24
- dicts = json.loads(r.text)
25
- if dicts["errcode"] == 0:
26
- return True,dicts
27
- else:
28
- return False,dicts
29
- else:
30
- return False, errString
31
-
32
- def uploadFile(self, files):
33
- headers = {
34
- "Content-Type": "multipart/form-data;"
35
- }
36
- r = requests.post(self.url, files=files, headers=headers)
37
- # BoolResult, errString, r = self.bsrequest.base_request_post(self.url,
38
- # headers=headers,
39
- # files=upfile,
40
- # timeout=(10, 30)
41
- # )
42
- print(r.text)
43
-
44
- def sendTextMsg(self,msg,options=None):
45
- data = {
46
- "msgtype": "text",
47
- "text": {
48
- "content": msg
49
- }
50
- }
51
- if options:
52
- data["text"] .update(options)
53
- return self.sendMsg(data)
54
-
55
- def sendMarkDownMsg(self,msg,options=None):
56
- data = {
57
- "msgtype": "markdown",
58
- "markdown": {
59
- "content": msg
60
- }
61
- }
62
- if options:
63
- data["text"] .update(options)
64
- return self.sendMsg(data)
65
-
66
- def sendImage(self, msg):
67
- data = {
68
- "msgtype": "image",
69
- "image": msg
70
- }
71
- return self.sendMsg(data)
72
-
73
- def sendTxtImage(self, msg):
74
- data = {
75
- "msgtype": "news",
76
- "articles": msg
77
- }
78
- return self.sendMsg(data)
79
-
80
- if __name__ == "__main__":
81
- wxb = WorkWechatBot("5a822419-b7b2-4036-a136-5e75f028ddfb")
82
- #wxb.sendTextMsg("额...")
83
- files = {'file': ('test.txt',open(r'E:\test.txt', 'rb'),"media")}
84
- wxb.uploadFile(files)
File without changes