Spaces:
Paused
Paused
Download akipy/utils.py from mega345evolutions/Ultroid: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/mega345evolutions/Ultroid/resolve/main/akipy/utils.py
- Command line
-
hf download hf://spaces/mega345evolutions/Ultroid/akipy/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/mega345evolutions/Ultroid/resolve/main/akipy/utils.py
1.02 kB
| from typing import Union, Optional | |
| import httpx | |
| from .dicts import ANSWERS, HEADERS | |
| def request_handler(url: str, method: str, data: Optional[dict] = None) -> httpx.Response: | |
| if method == 'GET': | |
| return httpx.get(url, headers=HEADERS, timeout=30.0) | |
| elif method == 'POST': | |
| return httpx.post(url, headers=HEADERS, data=data, timeout=30.0) | |
| else: | |
| raise ValueError(f"Unsupported HTTP method: {method}") | |
| async def async_request_handler(url: str, method: str, data: Optional[dict] = None) -> httpx.Response: | |
| async with httpx.AsyncClient() as client: | |
| if method == 'GET': | |
| return await client.get(url, headers=HEADERS, timeout=30.0) | |
| elif method == 'POST': | |
| return await client.post(url, headers=HEADERS, data=data, timeout=30.0) | |
| else: | |
| raise ValueError(f"Unsupported HTTP method: {method}") | |
| def get_answer_id(ans): | |
| for key, values in ANSWERS.items(): | |
| if ans.lower() in values: | |
| return key | |
| return None | |