Spaces:
Sleeping
Sleeping
File size: 1,383 Bytes
c664d1d 11ae35a 9dc9174 89a7a7a ea508b7 89a7a7a ea508b7 89a7a7a c664d1d 89a7a7a 51e1c40 c664d1d 89a7a7a |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from asyncio import gather
# from Powers.bot_class import aiohttpsession as session
import requests
def get(url: str, *args, **kwargs):
resp = requests.get(url, *args, **kwargs)
if resp.status_code != 200:
return resp.status_code
try:
data = resp.json()
except Exception:
data = resp.text()
return data
def head(url: str, *args, **kwargs):
resp = requests.head(url, *args, **kwargs)
try:
data = resp.json()
except Exception:
data = resp.text()
return data
def post(url: str, *args, **kwargs):
resp = requests.post(url, *args, **kwargs)
if resp.status_code != 200:
return resp.status_code
try:
data = resp.json()
except Exception:
data = 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)])
def resp_get(url: str, *args, **kwargs):
return requests.get(url, *args, **kwargs)
def resp_post(url: str, *args, **kwargs):
return requests.post(url, *args, **kwargs)
|