mirror of https://github.com/miaowware/qrm2.git
convert urllib code to aiohttp
This commit is contained in:
parent
640ad9f8e3
commit
96d251fe47
|
@ -12,7 +12,7 @@ import discord.ext.commands as commands
|
||||||
|
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import urllib
|
import aiohttp
|
||||||
|
|
||||||
class StudyCog(commands.Cog):
|
class StudyCog(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -51,8 +51,11 @@ class StudyCog(commands.Cog):
|
||||||
'(Note that only the US question pools are available).')
|
'(Note that only the US question pools are available).')
|
||||||
return
|
return
|
||||||
|
|
||||||
with urllib.request.urlopen(f'https://hamstudy.org/pools/{selected_pool}') as url:
|
async with aiohttp.ClientSession() as session:
|
||||||
pool = json.loads(url.read().decode())['pool']
|
async with session.get(f'https://hamstudy.org/pools/{selected_pool}') as resp:
|
||||||
|
if resp.status != 200:
|
||||||
|
return await ctx.send('Could not load questions...')
|
||||||
|
pool = json.loads(await resp.read())['pool']
|
||||||
|
|
||||||
# Select a question
|
# Select a question
|
||||||
pool_section = random.choice(pool)['sections']
|
pool_section = random.choice(pool)['sections']
|
||||||
|
|
Loading…
Reference in New Issue