Spaces:
Paused
Paused
Download Powers/utils/http_helper.py from Dragdev/telegrambot: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/Dragdev/telegrambot/resolve/492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/http_helper.py
- Command line
-
hf download hf://spaces/Dragdev/telegrambot@492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/http_helper.py
-
curl -L -o http_helper.py https://huggingface.co/spaces/Dragdev/telegrambot/resolve/492d7fcd90594de1ce93896bb2a9b2f9e1927150/Powers/utils/http_helper.py
1.4 kB
| from asyncio import gather | |
| from Powers.bot_class import aiohttpsession as session | |
| async def get(url: str, *args, **kwargs): | |
| async with session.get(url, *args, **kwargs) as resp: | |
| try: | |
| data = await resp.json() | |
| except Exception: | |
| data = await resp.text() | |
| return data | |
| async def head(url: str, *args, **kwargs): | |
| async with session.head(url, *args, **kwargs) as resp: | |
| try: | |
| data = await resp.json() | |
| except Exception: | |
| data = await resp.text() | |
| return data | |
| async def post(url: str, *args, **kwargs): | |
| async with session.post(url, *args, **kwargs) as resp: | |
| try: | |
| data = await resp.json() | |
| except Exception: | |
| data = await resp.text() | |
| return data | |
| async def multiget(url: str, times: int, *args, **kwargs): | |
| return await gather(*[get(url, *args, **kwargs) for _ in range(times)]) | |
| async def multihead(url: str, times: int, *args, **kwargs): | |
| return await gather(*[head(url, *args, **kwargs) for _ in range(times)]) | |
| async def multipost(url: str, times: int, *args, **kwargs): | |
| return await gather(*[post(url, *args, **kwargs) for _ in range(times)]) | |
| async def resp_get(url: str, *args, **kwargs): | |
| return await session.get(url, *args, **kwargs) | |
| async def resp_post(url: str, *args, **kwargs): | |
| return await session.post(url, *args, **kwargs) | |