XMWAI 0.1.7__py3-none-any.whl → 0.1.81__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 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
- if mode == 0:
17
- with open("idiom.json", "r", encoding="utf-8") as f:
18
- data = json.load(f)
19
- for i in data:
20
- if word == i["word"]:
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
- return False
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
- return None
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
- return None
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 mode: 第几个字
52
- :return: 查询结果None
42
+ :param num: 第几个字(1~4)
43
+ :return: 匹配的成语False
53
44
  """
54
45
  wordList = []
55
- with open("idiom.json", "r", encoding="utf-8") as f:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: XMWAI
3
- Version: 0.1.7
3
+ Version: 0.1.81
4
4
  Summary: Small code King AI related library
5
5
  Home-page: https://github.com/Tonykai88/XMWAI.git
6
6
  Author: pydevelopment
@@ -1,7 +1,8 @@
1
- XMWAI/__init__.py,sha256=GuNnfM345TTSZW45YiwEt1dM6Ay0biP1bQBrGpqqmEg,464
1
+ XMWAI/__init__.py,sha256=2ZiaoXUtLQ6YFSyb7Q7iOulKRLK128ddeBdYBbcIyww,494
2
2
  XMWAI/bomb_core.py,sha256=dRORqAyhItkFuMUHAN0vwQcvrvb3C5X18hmaUMJ0hhE,1708
3
3
  XMWAI/core.py,sha256=KrtdKXvSGKAHlOYF1-v2iSxpfjpHoGeGVOBIxH1Ez4E,7759
4
- XMWAI/idiom_core.py,sha256=H3OhYbcGeyGwibrgq2JLHlYD5eVmxVJAmKyFFYn88cY,1839
4
+ XMWAI/idiom.json,sha256=HUtPRUzhxBbWoasjadbmbA_5ngQ5AXLu9weQSZ4hzhk,10319857
5
+ XMWAI/idiom_core.py,sha256=0Uu9GxVwEvFAhjj0M2Orw-E9FjKT05jKQDbUvg0wAXE,1577
5
6
  XMWAI/magic_core.py,sha256=XU7K4Ta7EAvwBLk20_Hlu18E6Kz8B0HxUBq0YsawikE,3441
6
7
  XMWAI/gif/0.gif,sha256=LGpAReVTyZEb1J-bWYTpxxHbIxmLJ-3wA0lw4cBqdsY,303
7
8
  XMWAI/gif/1.gif,sha256=nsysRjMkNBQJy91SOY284gnnD_DlhLrgyIOgcJ_ZOHI,3554
@@ -90,8 +91,8 @@ XMWAI/gif/84.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
90
91
  XMWAI/gif/85.gif,sha256=6Ip_uQmvrr2fagLXu1YqWyI_DL2PVVtKCPtmNtzt3P4,38767
91
92
  XMWAI/gif/9.gif,sha256=cPouth-xwc3QPcg2m6HMP2OD1ZCeRBD_-RPImvvKAA0,9485
92
93
  XMWAI/gif/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
93
- xmwai-0.1.7.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
94
- xmwai-0.1.7.dist-info/METADATA,sha256=Brl-47g-2N-wyM20O9Mhepb4Y5_lPTE4McoFcMiGICc,1033
95
- xmwai-0.1.7.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
96
- xmwai-0.1.7.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
97
- xmwai-0.1.7.dist-info/RECORD,,
94
+ xmwai-0.1.81.dist-info/licenses/LICENSE.txt,sha256=bcaIQMrIhdQ3O-PoZlexjmW6h-wLGvHxh5Oksl4ohtc,1066
95
+ xmwai-0.1.81.dist-info/METADATA,sha256=6JT1a0mg5Hxa_nQcjxBcyv28zNUXPTG7LNrEHRJU_Ek,1034
96
+ xmwai-0.1.81.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
97
+ xmwai-0.1.81.dist-info/top_level.txt,sha256=yvGcDI-sggK5jqd9wz0saipZvk3oIE3hNGHlqUjxf0c,6
98
+ xmwai-0.1.81.dist-info/RECORD,,
File without changes