forked from pawankm21/discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
45 lines (36 loc) · 1.67 KB
/
utils.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
38
39
40
41
42
43
44
45
import aiohttp
import asyncio
import random
class WebSession:
session = aiohttp.ClientSession()
session_bak = aiohttp.ClientSession()
async def webget_text(self, url, headers={}):
headers['User-Agent'] = 'Mozilla/5.0'
async with random.choice(
(self.session_bak, self.session)).get(url,
headers=headers) as resp:
return await resp.text()
async def webget_json(self, url, headers={}):
async with random.choice(
(self.session_bak, self.session)).get(url,
headers=headers) as resp:
return await resp.json(content_type=None)
async def webpost(self, url, data={}, headers={}):
async with random.choice(
(self.session_bak, self.session)).post(url,
data=data,
headers=headers) as resp:
return resp
async def webpost_text(self, url, data={}, headers={}):
async with random.choice(
(self.session_bak, self.session)).post(url,
data=data,
headers=headers) as resp:
return await resp.text()
async def webpost_json(self, url, json={}, headers={}):
async with random.choice(
(self.session_bak, self.session)).post(url,
json=json,
headers=headers) as resp:
return await resp.json(content_type=None)
webc = WebSession()