Browse Source

Make bot async so it doesn't break when the timings site is down

pull/16/head
Purpur 4 years ago
committed by GitHub
parent
commit
a3540300e3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      cogs/timings.py

9
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.")

Loading…
Cancel
Save