aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2020-11-17 16:44:05 +0200
committerGravatar ks129 <[email protected]>2020-11-17 16:44:05 +0200
commit0191ae3c54a4fc459ab392eaf5aa9743aa2801c3 (patch)
tree97784c98a7f7caaeeea3b36cdeb0f95234346ba6
parentMove GitHub API key to better location (diff)
Use GitHub token for fetching PEPs
-rw-r--r--bot/exts/utils/utils.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/bot/exts/utils/utils.py b/bot/exts/utils/utils.py
index 6d8d98695..59c472cf9 100644
--- a/bot/exts/utils/utils.py
+++ b/bot/exts/utils/utils.py
@@ -11,7 +11,7 @@ from discord import Colour, Embed, utils
from discord.ext.commands import BadArgument, Cog, Context, clean_content, command, has_any_role
from bot.bot import Bot
-from bot.constants import Channels, MODERATION_ROLES, STAFF_ROLES
+from bot.constants import Channels, Keys, MODERATION_ROLES, STAFF_ROLES
from bot.decorators import in_whitelist
from bot.pagination import LinePaginator
from bot.utils import messages
@@ -45,6 +45,11 @@ ICON_URL = "https://www.python.org/static/opengraph-icon-200x200.png"
pep_cache = AsyncCache()
+# Add GitHub token when it's set to raise limit of requests per hour
+GITHUB_HEADERS = {}
+if Keys.github:
+ GITHUB_HEADERS["Authorization"] = f"token {Keys.github}"
+
class Utils(Cog):
"""A selection of utilities which don't have a clear category."""
@@ -197,7 +202,7 @@ class Utils(Cog):
await self.bot.wait_until_ready()
log.trace("Started refreshing PEP URLs.")
- async with self.bot.http_session.get(self.PEPS_LISTING_API_URL) as resp:
+ async with self.bot.http_session.get(self.PEPS_LISTING_API_URL, headers=GITHUB_HEADERS) as resp:
listing = await resp.json()
log.trace("Got PEP URLs listing from GitHub API")