From a3540300e3b39a577ff95a4a288fe7143c767b91 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Fri, 5 Feb 2021 22:41:03 -0600 Subject: [PATCH] Make bot async so it doesn't break when the timings site is down --- cogs/timings.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cogs/timings.py b/cogs/timings.py index 74271ac..4a8dc19 100644 --- a/cogs/timings.py +++ b/cogs/timings.py @@ -1,6 +1,6 @@ import discord from discord.ext import commands -import requests +import aiohttp import yaml import re import logging @@ -57,8 +57,11 @@ class Timings(commands.Cog): timings_json = timings_host + "data.php?id=" + timings_id timings_url_raw = timings_url + "&raw=1" - request_raw = requests.get(timings_url_raw).json() - request = requests.get(timings_json).json() + async with aiohttp.ClientSession() as session: + async with session.get(timings_url_raw) as response: + request_raw = response.json() + async with session.get(timings_json) as response: + request = response.json() if request is None or request_raw is None: embed_var.add_field(name="❌ Invalid report", value="Create a new timings report.")