lesscode-tag 0.0.6__tar.gz → 0.0.7__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lesscode_tag
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: lesscode_tag是标签处理工具包
5
5
  Author: Chao.yy
6
6
  Author-email: yuyc@ishangqi.com
@@ -1,4 +1,4 @@
1
- from lesscode_tag.es_util import es_condition_by_terms, es_condition_by_wildcard
1
+ from lesscode_utils.es_utils import es_condition_by_terms, es_condition_by_wildcard
2
2
 
3
3
 
4
4
  def get_single_tag_condition(tag):
@@ -109,7 +109,6 @@ def format_param_tag(bool_should_more_list, especial_tag_list):
109
109
  if tag in ["规上企业"]:
110
110
  es_condition_by_terms(bool_should_list, "tags.nonpublic_tag", [tag])
111
111
  bool_should_more_list.append(bool_should_list)
112
- return bool_should_more_list
113
112
 
114
113
 
115
114
  def parse_special_tag_new(tags, tags_param_list=None):
@@ -0,0 +1 @@
1
+ __version__ = "0.0.7"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lesscode-tag
3
- Version: 0.0.6
3
+ Version: 0.0.7
4
4
  Summary: lesscode_tag是标签处理工具包
5
5
  Author: Chao.yy
6
6
  Author-email: yuyc@ishangqi.com
@@ -1,11 +1,10 @@
1
1
  README.md
2
2
  setup.py
3
3
  lesscode_tag/__init__.py
4
- lesscode_tag/aes.py
5
4
  lesscode_tag/business.py
6
- lesscode_tag/es_util.py
7
5
  lesscode_tag/version.py
8
6
  lesscode_tag.egg-info/PKG-INFO
9
7
  lesscode_tag.egg-info/SOURCES.txt
10
8
  lesscode_tag.egg-info/dependency_links.txt
9
+ lesscode_tag.egg-info/requires.txt
11
10
  lesscode_tag.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ lesscode_utils>=0.0.1
@@ -24,6 +24,7 @@ setuptools.setup(
24
24
  platforms='python',
25
25
  install_requires=[
26
26
  # "pycryptodomex==3.17"
27
+ "lesscode_utils>=0.0.1"
27
28
  ]
28
29
 
29
30
  )
@@ -46,6 +47,6 @@ twine upload dist/*
46
47
  twine upload dist/* -u yuyc -p yu230225
47
48
  twine upload dist/* --repository-url https://pypi.chanyeos.com/ -u admin -p shangqi
48
49
  # 安装最新的版本测试
49
- pip install -U lesscode_charts -i https://pypi.org/simple
50
- pip install -U lesscode_charts -i https://pypi.chanyeos.com/simple
50
+ pip install -U lesscode_tag -i https://pypi.org/simple
51
+ pip install -U lesscode_tag -i https://pypi.chanyeos.com/simple
51
52
  """
@@ -1,51 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- import base64
3
- import binascii
4
- import importlib
5
-
6
-
7
- class AES:
8
- @staticmethod
9
- def encrypt(key="haohaoxuexi", text=""):
10
- """
11
- :param key: 密钥
12
- :param text: 需要被加密的数据
13
- """
14
- try:
15
- _AES = importlib.import_module("Cryptodome.Cipher.AES")
16
- except ImportError:
17
- raise Exception(f"pycryptodomex is not exist,run:pip install pycryptodomex==3.17")
18
- text = str(text)
19
- aes = _AES.new(AES.add_to_16(key), _AES.MODE_ECB)
20
- encrypt_aes = aes.encrypt(AES.add_to_16(text))
21
- encrypted_text = str(base64.encodebytes(encrypt_aes), encoding='utf-8')
22
- return bytes.decode(binascii.b2a_hex(bytes(encrypted_text, encoding="utf8")))
23
-
24
- @staticmethod
25
- def decrypt(key="haohaoxuexi", text=""):
26
- """
27
- :param key: 密钥
28
- :param text: 需要被加密的数据
29
- """
30
- try:
31
- _AES = importlib.import_module("Cryptodome.Cipher.AES")
32
- except ImportError:
33
- raise Exception(f"pycryptodomex is not exist,run:pip install pycryptodomex==3.17")
34
- text = bytes.decode(binascii.a2b_hex(bytes(text, encoding="utf8")))
35
- # 密文
36
- # 初始化加密器
37
- aes = _AES.new(AES.add_to_16(key), _AES.MODE_ECB)
38
- # 优先逆向解密base64成bytes
39
- base64_decrypted = base64.decodebytes(text.encode(encoding='utf-8'))
40
- # 执行解密密并转码返回str
41
- decrypted_text = str(aes.decrypt(base64_decrypted), encoding='utf-8').replace('\0', '')
42
- return decrypted_text
43
-
44
- @staticmethod
45
- def add_to_16(value):
46
- """
47
- :param value: 待处理的数据
48
- """
49
- while len(value) % 16 != 0:
50
- value += '\0'
51
- return str.encode(value) # 返回bytes
@@ -1,302 +0,0 @@
1
- from lesscode_tag.aes import AES
2
-
3
-
4
- def format_company_id_en(value, route_key, key="haohaoxuexi"):
5
- if route_key in ["core.patent", "core.patent_lite"]:
6
- for data in value.get("tags", {}).get("proposer_type", []):
7
- if data.get("code"):
8
- data["code"] = AES.encrypt(key, data["code"])
9
- elif route_key in ["core.research_institution"]:
10
- for data in value.get("tags", {}).get("support_unit", []):
11
- if data.get("id"):
12
- data["id"] = AES.encrypt(key, data["id"])
13
- elif route_key in ["core.investment"]:
14
- for data in value.get("tags", {}).get("invest_company", []):
15
- if data.get("company_id"):
16
- data["company_id"] = AES.encrypt(key, data["company_id"])
17
-
18
-
19
- def format_es_param_result(r, param_list, is_need_decrypt, is_need_es_score, route_key, key="haohaoxuexi"):
20
- result_dict = {}
21
- format_company_id_en(r["_source"], route_key)
22
- if param_list and r["_source"]:
23
- for key in param_list:
24
- value = r["_source"]
25
- key_list = key.split(".")
26
- for key in key_list:
27
- if isinstance(value, list):
28
- if value:
29
- result = []
30
- for v in value:
31
- if isinstance(v.get(key, None), list):
32
- result = result + v[key]
33
- else:
34
- result.append(v.get(key, None))
35
- value = result
36
- elif isinstance(value, dict):
37
- if value:
38
- value = value.get(key, None)
39
- else:
40
- pass
41
- if result_dict.get(key) is None:
42
- if value is not None:
43
- result_dict[key] = value
44
- else:
45
- result_dict = r["_source"]
46
- if is_need_decrypt:
47
- r["_id"] = AES.encrypt(key)
48
- result_dict["_id"] = r["_id"]
49
- if is_need_es_score:
50
- result_dict["_score"] = r["_score"]
51
- return result_dict
52
-
53
-
54
- def es_condition_by_match_phrase(bool_list, column, param, slop=0):
55
- if param:
56
- if isinstance(param, list):
57
- bool_list.append({
58
- "match_phrase": {
59
- column: {
60
- "query": param[0],
61
- "slop": slop
62
- }
63
- }
64
- })
65
- if isinstance(param, str):
66
- bool_list.append({
67
- "match_phrase": {
68
- column: {
69
- "query": param,
70
- "slop": slop
71
- }
72
- }
73
- })
74
-
75
-
76
- def es_condition_by_match(bool_list, column, param):
77
- if param:
78
- if isinstance(param, list):
79
- bool_list.append({
80
- "match": {
81
- column: {
82
- "query": param[0],
83
- }
84
- }
85
- })
86
- if isinstance(param, str):
87
- bool_list.append({
88
- "match": {
89
- column: {
90
- "query": param,
91
- }
92
- }
93
- })
94
-
95
-
96
- def es_condition_by_not_null(boo_must_list, column, param):
97
- if param:
98
- boo_must_list.append({
99
- "exists": {
100
- "field": column
101
- }
102
- })
103
-
104
-
105
- def es_condition_by_range(bool_must_list, column, date_list, is_contain_end_date=False, is_contain_start_date=True):
106
- if date_list:
107
- range_dict = {}
108
- if date_list[0]:
109
- if is_contain_start_date:
110
- range_dict["gte"] = date_list[0]
111
- else:
112
- range_dict["gt"] = date_list[0]
113
- if len(date_list) == 2 and date_list[1]:
114
- end = date_list[1]
115
- if is_contain_end_date:
116
- range_dict["lte"] = end
117
- else:
118
- range_dict["lt"] = end
119
-
120
- if range_dict:
121
- bool_must_list.append({
122
- "range": {
123
- column: range_dict
124
- }})
125
-
126
-
127
- def es_condition_by_terms(bool_must_list, column, param_list, is_need_decrypt=False, key="haohaoxuexi"):
128
- if param_list:
129
- param_list = [i for i in param_list if i not in [None, "", "all"]]
130
- if is_need_decrypt:
131
- for index, _id in enumerate(param_list):
132
- # noinspection PyBroadException
133
- try:
134
- _id = AES.decrypt(key, _id)
135
- param_list[index] = int(_id)
136
- except Exception:
137
- pass
138
- if param_list:
139
- bool_must_list.append({
140
- "terms": {
141
- column: param_list
142
- }})
143
-
144
-
145
- def es_condition_by_wildcard(bool_list, column, param):
146
- if param:
147
- bool_list.append({"wildcard": {column: f"*{param}*"}})
148
-
149
-
150
- def es_condition_by_exist(bool_must_list, param, is_exists="是"):
151
- if param:
152
- if is_exists == "是" or is_exists == "true" or is_exists is True:
153
- bool_must_list.append({
154
- "exists": {
155
- "field": param
156
- }})
157
- else:
158
- bool_must_list.append({
159
- "bool": {
160
- "must_not": [
161
- {
162
- "exists": {
163
- "field": param
164
- }
165
- }
166
- ]
167
- }
168
- })
169
-
170
-
171
- def es_condition_by_exist_or_not(bool_must_list, param_dict):
172
- if param_dict:
173
- for key in param_dict:
174
- if param_dict[key] in ["是", "true", True]:
175
- bool_must_list.append({
176
- "exists": {
177
- "field": key
178
- }})
179
- else:
180
- bool_must_list.append({
181
- "bool": {
182
- "must_not": [
183
- {
184
- "exists": {
185
- "field": key
186
- }
187
- }
188
- ]
189
- }
190
- })
191
-
192
-
193
- def es_condition_by_not_in(bool_must_list: list = None, column="", param_list=None):
194
- if param_list:
195
- bool_must_list.append({
196
- "bool": {
197
- "must_not": {
198
- "terms": {
199
- column: param_list
200
- }}
201
- }
202
- })
203
-
204
-
205
- def es_condition_by_geo_shape(bool_must_list: list = None, column="", polygon=None, geo_type="MultiPolygon",
206
- relation="intersects"):
207
- if polygon:
208
- bool_must_list.append({
209
- "geo_shape": {
210
- column: {
211
- "shape": {
212
- "type": geo_type,
213
- "coordinates": polygon
214
- },
215
- "relation": relation
216
- }
217
- }
218
- })
219
-
220
-
221
- def format_bool_must_and_should(bool_must_list, bool_should_more_list):
222
- if bool_should_more_list:
223
- for bool_should in bool_should_more_list:
224
- bool_must_list.append({
225
- "bool": {
226
- "should": bool_should
227
- }
228
- })
229
-
230
-
231
- def format_bool_must_and_must_not(bool_must_list, bool_must_not_more_list):
232
- if bool_must_not_more_list:
233
- for bool_must_not in bool_must_not_more_list:
234
- bool_must_list.append({
235
- "bool": {
236
- "must_not": bool_must_not
237
- }
238
- })
239
-
240
-
241
- def parse_es_sort_list(column=None, order=None):
242
- if column and order:
243
- if order == "asc":
244
- sort_list = [
245
- {
246
- column: {
247
- "order": order,
248
- "missing": "_last"
249
- }
250
- }
251
- ]
252
- else:
253
- sort_list = [
254
- {
255
- column: {
256
- "order": order,
257
- "missing": "_last"
258
- }
259
- }
260
- ]
261
- else:
262
- sort_list = []
263
-
264
- return sort_list
265
-
266
-
267
- def es_condition_by_geo_distance(bool_must_list: list = None, column="", geo_distance=None):
268
- if geo_distance:
269
- bool_must_list.append({
270
- "geo_distance": {
271
- "distance": "{}{}".format(geo_distance.get("radius", 0), geo_distance.get("unit", "km")),
272
- column: {
273
- "lat": geo_distance.get("lat", 0),
274
- "lon": geo_distance.get("lon", 0),
275
- }
276
- }
277
- })
278
-
279
-
280
- def es_mapping2dict(mapping):
281
- mapping_dict = dict()
282
-
283
- if isinstance(mapping, dict):
284
- if "properties" in mapping:
285
- for k, v in mapping.get("properties").items():
286
- if isinstance(v, dict):
287
- if "properties" not in v:
288
- if "fields" not in v and "type" in v:
289
- field_type = v.get("type")
290
- mapping_dict[k] = field_type
291
- elif "fields" in v and "type" in v:
292
- field_type = v.get("type")
293
- mapping_dict[k] = field_type
294
- if isinstance(v.get("fields"), dict):
295
- for fk, fv in v.get("fields").items():
296
- if "type" in fv:
297
- mapping_dict[f"{k}.{fk}"] = fv.get("type")
298
-
299
- else:
300
- mapping_dict[k] = es_mapping2dict(v)
301
-
302
- return mapping_dict
@@ -1 +0,0 @@
1
- __version__ = "0.0.6"
File without changes
File without changes