didier/didier/data/apis/urban_dictionary.py

18 lines
543 B
Python
Raw Normal View History

from aiohttp import ClientSession
from didier.data.embeds.urban_dictionary import Definition
2022-09-22 02:04:34 +02:00
from didier.utils.http.requests import ensure_get
2022-07-14 20:28:45 +02:00
__all__ = ["lookup", "PER_PAGE"]
PER_PAGE = 10
2022-09-22 02:04:34 +02:00
async def lookup(http_session: ClientSession, query: str) -> list[Definition]:
"""Fetch the Urban Dictionary definitions for a given word"""
url = "https://api.urbandictionary.com/v0/define"
2022-09-22 02:04:34 +02:00
async with ensure_get(http_session, url, params={"term": query}) as response:
return list(map(Definition.parse_obj, response["list"]))