Changed downloading doggo images to use aiohttp
This commit is contained in:
parent
2d9c2a8e87
commit
901c81823e
1 changed files with 6 additions and 1 deletions
|
@ -8,6 +8,7 @@ import glob
|
||||||
import sys
|
import sys
|
||||||
import discord
|
import discord
|
||||||
import inspect
|
import inspect
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
getter = re.compile(r'`(?!`)(.*?)`')
|
getter = re.compile(r'`(?!`)(.*?)`')
|
||||||
multi = re.compile(r'```(.*?)```', re.DOTALL)
|
multi = re.compile(r'```(.*?)```', re.DOTALL)
|
||||||
|
@ -36,7 +37,11 @@ class Owner:
|
||||||
"""Saves a URL as an image to add for the doggo command"""
|
"""Saves a URL as an image to add for the doggo command"""
|
||||||
os.chdir('/home/phxntx5/public_html/Bonfire/images')
|
os.chdir('/home/phxntx5/public_html/Bonfire/images')
|
||||||
local_path = 'doggo{}.jpg'.format(len(glob.glob('doggo*')))
|
local_path = 'doggo{}.jpg'.format(len(glob.glob('doggo*')))
|
||||||
urllib.request.urlretrieve(url, local_path)
|
with aiohttp.ClientSession() as s:
|
||||||
|
async with s.get(url) as r:
|
||||||
|
val = await r.read()
|
||||||
|
with open(local_path, "wb") as f:
|
||||||
|
f.write(val)
|
||||||
await self.bot.say(
|
await self.bot.say(
|
||||||
"Just saved a new doggo image! You now have {} doggo images!".format(len(glob.glob('doggo*'))))
|
"Just saved a new doggo image! You now have {} doggo images!".format(len(glob.glob('doggo*'))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue