45 lines
958 B
Python
45 lines
958 B
Python
|
import csv
|
||
|
from os import sep
|
||
|
from typing import List
|
||
|
|
||
|
handbook = {}
|
||
|
handbook_max = 15
|
||
|
|
||
|
|
||
|
class HandBook:
|
||
|
def __init__(self, uid: str, name: str):
|
||
|
self.uid = uid
|
||
|
self.name = name
|
||
|
|
||
|
|
||
|
with open(f"resources{sep}Handbook_CHS.csv", "r", encoding="utf-8") as f:
|
||
|
reader = csv.reader(f)
|
||
|
for row in reader:
|
||
|
if row[0] == "":
|
||
|
continue
|
||
|
handbook[row[0]] = HandBook(row[0], row[1])
|
||
|
|
||
|
|
||
|
def find(words: List) -> List[HandBook]:
|
||
|
"""search a word in the handbook.
|
||
|
|
||
|
Args:
|
||
|
words: The words to find.
|
||
|
|
||
|
Returns:
|
||
|
A list of definitions.
|
||
|
"""
|
||
|
data, count = [], 0
|
||
|
for key, value in handbook.items():
|
||
|
add = False
|
||
|
for word in words:
|
||
|
if word.lower() in value.name.lower():
|
||
|
add = True
|
||
|
break
|
||
|
if add:
|
||
|
data.append(value)
|
||
|
count += 1
|
||
|
if count == handbook_max:
|
||
|
break
|
||
|
return data
|