-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdefine.py
32 lines (25 loc) · 803 Bytes
/
define.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright (c) 2022 - Itz-fork
from fastapi import APIRouter
from PyDictionary import PyDictionary
from ..models.Languages import DefineModel
from ..functions.asyncnx import run_async
from ..functions.response import send_response
route = APIRouter()
def define(word):
dic = PyDictionary()
mn = dic.meaning(word)
result = {}
if isinstance(mn, dict):
# Iterate through key value pairs of the dict (definitely not dick)
for k, v in mn.items():
result["type"] = k
result["definition"] = v
return result
@route.get(
"/define",
description="Get the definition of a word",
response_model=DefineModel,
tags=["Language"])
async def define_word(word: str):
x = await run_async(define, word)
return await send_response(x)