Let's not be deprecated again

Changed `aiohttp.get` to use `aiohttp.ClientSession()`
This commit is contained in:
Yukirin
2018-02-01 06:12:59 +08:00
committed by GitHub
parent 93465b2140
commit 2b5e99b403

View File

@@ -56,6 +56,10 @@ class ImgWelcome:
self.bot = bot
self.settings = dataIO.load_json('data/imgwelcome/settings.json')
self.version = "0.1.6"
self.session = aiohttp.ClientSession()
def __unload(self):
self.session.close()
async def save_settings(self):
dataIO.save_json('data/imgwelcome/settings.json', self.settings)
@@ -220,7 +224,7 @@ class ImgWelcome:
await self.save_settings()
async def _get_profile(self, url):
async with aiohttp.get(url) as r:
async with self.session.get(url) as r:
image = await r.content.read()
with open('data/imgwelcome/profilepic.png', 'wb') as f:
f.write(image)
@@ -407,7 +411,7 @@ class ImgWelcome:
if success:
try:
async with aiohttp.get(bg_url) as r:
async with self.session.get(bg_url) as r:
image = await r.content.read()
if not os.path.exists('data/imgwelcome/{}'.format(server.id)):
os.makedirs('data/imgwelcome/{}'.format(server.id))