XMWAI 0.1.7__py3-none-any.whl → 0.1.8__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.
Potentially problematic release.
This version of XMWAI might be problematic. Click here for more details.
- XMWAI/idiom_core.py +21 -33
- {xmwai-0.1.7.dist-info → xmwai-0.1.8.dist-info}/METADATA +1 -1
- {xmwai-0.1.7.dist-info → xmwai-0.1.8.dist-info}/RECORD +6 -6
- {xmwai-0.1.7.dist-info → xmwai-0.1.8.dist-info}/WHEEL +0 -0
- {xmwai-0.1.7.dist-info → xmwai-0.1.8.dist-info}/licenses/LICENSE.txt +0 -0
- {xmwai-0.1.7.dist-info → xmwai-0.1.8.dist-info}/top_level.txt +0 -0
XMWAI/idiom_core.py
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import random
|
|
2
2
|
import json
|
|
3
|
+
from importlib.resources import files
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def get_json_path():
|
|
8
|
+
"""获取 idiom.json 的正确路径(兼容 PyPI 安装后的包内资源)"""
|
|
9
|
+
return Path(files("XMWAI").joinpath("idiom.json"))
|
|
3
10
|
|
|
4
11
|
|
|
5
12
|
def idiom(word, mode=0):
|
|
@@ -13,54 +20,35 @@ def idiom(word, mode=0):
|
|
|
13
20
|
3 - 返回出处
|
|
14
21
|
:return: 查询结果或 None
|
|
15
22
|
"""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if
|
|
23
|
+
with open(get_json_path(), "r", encoding="utf-8") as f:
|
|
24
|
+
data = json.load(f)
|
|
25
|
+
for i in data:
|
|
26
|
+
if word == i["word"]:
|
|
27
|
+
if mode == 0:
|
|
21
28
|
return True
|
|
22
|
-
|
|
23
|
-
elif mode == 1:
|
|
24
|
-
with open("idiom.json", "r", encoding="utf-8") as f:
|
|
25
|
-
data = json.load(f)
|
|
26
|
-
for i in data:
|
|
27
|
-
if word == i["word"]:
|
|
29
|
+
elif mode == 1:
|
|
28
30
|
return i["pinyin"]
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
elif mode == 2:
|
|
32
|
-
with open("idiom.json", "r", encoding="utf-8") as f:
|
|
33
|
-
data = json.load(f)
|
|
34
|
-
for i in data:
|
|
35
|
-
if word == i["word"]:
|
|
31
|
+
elif mode == 2:
|
|
36
32
|
return i["explanation"]
|
|
37
|
-
|
|
38
|
-
elif mode == 3:
|
|
39
|
-
with open("idiom.json", "r", encoding="utf-8") as f:
|
|
40
|
-
data = json.load(f)
|
|
41
|
-
for i in data:
|
|
42
|
-
if word == i["word"]:
|
|
33
|
+
elif mode == 3:
|
|
43
34
|
return i["derivation"]
|
|
44
|
-
return None
|
|
35
|
+
return False if mode == 0 else None
|
|
45
36
|
|
|
46
37
|
|
|
47
38
|
def searchIdiom(text, num=1):
|
|
48
39
|
"""
|
|
49
40
|
模糊查询成语
|
|
50
41
|
:param text: 要查询的字
|
|
51
|
-
:param
|
|
52
|
-
:return:
|
|
42
|
+
:param num: 第几个字(1~4)
|
|
43
|
+
:return: 匹配的成语 或 False
|
|
53
44
|
"""
|
|
54
45
|
wordList = []
|
|
55
|
-
with open(
|
|
46
|
+
with open(get_json_path(), "r", encoding="utf-8") as f:
|
|
56
47
|
data = json.load(f)
|
|
57
48
|
for i in data:
|
|
58
49
|
try:
|
|
59
|
-
if text == i["word"][num-1]:
|
|
50
|
+
if text == i["word"][num - 1]:
|
|
60
51
|
wordList.append(i["word"])
|
|
61
52
|
except:
|
|
62
53
|
pass
|
|
63
|
-
if wordList
|
|
64
|
-
return random.choice(wordList)
|
|
65
|
-
else:
|
|
66
|
-
return False
|
|
54
|
+
return random.choice(wordList) if wordList else False
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
XMWAI/__init__.py,sha256=GuNnfM345TTSZW45YiwEt1dM6Ay0biP1bQBrGpqqmEg,464
|
|
2
2
|
XMWAI/bomb_core.py,sha256=dRORqAyhItkFuMUHAN0vwQcvrvb3C5X18hmaUMJ0hhE,1708
|
|
3
3
|
XMWAI/core.py,sha256=KrtdKXvSGKAHlOYF1-v2iSxpfjpHoGeGVOBIxH1Ez4E,7759
|
|
4
|
-
XMWAI/idiom_core.py,sha256=
|
|
4
|
+
XMWAI/idiom_core.py,sha256=0Uu9GxVwEvFAhjj0M2Orw-E9FjKT05jKQDbUvg0wAXE,1577
|
|
5
5
|
XMWAI/magic_core.py,sha256=XU7K4Ta7EAvwBLk20_Hlu18E6Kz8B0HxUBq0YsawikE,3441
|
|
6
6
|
XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
|
|
7
7
|
XMWAI/gif/1.gif,sha256=nsysRjMkNBQJy91SOY284gnnD_DlhLrgyIOgcJ_ZOHI,3554
|
|
@@ -90,8 +90,8 @@ XMWAI/gif/84.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
|
|
|
90
90
|
XMWAI/gif/85.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
|
|
91
91
|
XMWAI/gif/9.gif,sha256=cPouth-xwc3QPcg2m6HMP2OD1ZCeRBD_-RPImvvKAA0,9485
|
|
92
92
|
XMWAI/gif/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
93
|
-
xmwai-0.1.
|
|
94
|
-
xmwai-0.1.
|
|
95
|
-
xmwai-0.1.
|
|
96
|
-
xmwai-0.1.
|
|
97
|
-
xmwai-0.1.
|
|
93
|
+
xmwai-0.1.8.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
|
|
94
|
+
xmwai-0.1.8.dist-info/METADATA,sha256=CJgI9oxFUvO-a7Ax4XNIQ5AOEz-t_O-p2doxPSDIIIk,1033
|
|
95
|
+
xmwai-0.1.8.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
96
|
+
xmwai-0.1.8.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
|
|
97
|
+
xmwai-0.1.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|