-
Notifications
You must be signed in to change notification settings - Fork 6
/
urbandict.py
37 lines (31 loc) · 1.07 KB
/
urbandict.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
33
34
35
36
37
# Copyright (c) 2022 - Itz-fork
from fastapi import APIRouter
from ..functions.response import send_response
from ..functions.http_req import fetch
from ..config.basic import NX_Basic
from ..models.Search import UrbanDictModel
route = APIRouter()
@route.get(
"/ud",
description="Search for definitions in urban dictionary",
response_model=UrbanDictModel,
tags=["Search"])
async def urban_dict_search(q: str):
ur = (await fetch(NX_Basic["ud_api"].format(q)))["list"]
results = []
if ur:
for r in ur:
try:
data = {}
data["definition"] = r["definition"]
data["example"] = r["example"]
data["sounds"] = r["sound_urls"]
data["author"] = r["author"]
data["link"] = r["permalink"]
data["added_on"] = r["written_on"]
data["likes"] = r["thumbs_up"]
data["dislikes"] = r["thumbs_down"]
results.append(data)
except:
pass
return await send_response(results)