diff options
| author | 2020-09-30 23:33:03 -0400 | |
|---|---|---|
| committer | 2020-09-30 23:33:03 -0400 | |
| commit | ba12301b69aa347b705ed61e8250d948b514d23b (patch) | |
| tree | 5daa2c0c641ef6e7733dad1edbf3fa3ba6973240 /bot/exts/halloween/hacktoberstats.py | |
| parent | Merge pull request #466 from python-discord/joseph/hacktoberfest-fixes (diff) | |
Authenticate GitHub API requests for Hacktoberfest stats.
Also changed the user agent from `Discord Python Hacktoberbot` to `Python Discord Hacktoberbot`.
Diffstat (limited to '')
| -rw-r--r-- | bot/exts/halloween/hacktoberstats.py | 9 | 
1 files changed, 6 insertions, 3 deletions
| diff --git a/bot/exts/halloween/hacktoberstats.py b/bot/exts/halloween/hacktoberstats.py index 9dd0e1a4..3347dd8f 100644 --- a/bot/exts/halloween/hacktoberstats.py +++ b/bot/exts/halloween/hacktoberstats.py @@ -10,7 +10,7 @@ import aiohttp  import discord  from discord.ext import commands -from bot.constants import Channels, Month, WHITELISTED_CHANNELS +from bot.constants import Channels, Month, Tokens, WHITELISTED_CHANNELS  from bot.utils.decorators import in_month, override_in_channel  from bot.utils.persist import make_persistent @@ -20,6 +20,10 @@ CURRENT_YEAR = datetime.now().year  # Used to construct GH API query  PRS_FOR_SHIRT = 4  # Minimum number of PRs before a shirt is awarded  HACKTOBER_WHITELIST = WHITELISTED_CHANNELS + (Channels.hacktoberfest_2020,) +REQUEST_HEADERS = {"User-Agent": "Python Discord Hacktoberbot"} +if GITHUB_TOKEN := Tokens.github: +    REQUEST_HEADERS["Authorization"] = f"token {GITHUB_TOKEN}" +  class HacktoberStats(commands.Cog):      """Hacktoberfest statistics Cog.""" @@ -242,9 +246,8 @@ class HacktoberStats(commands.Cog):              f"&per_page={per_page}"          ) -        headers = {"user-agent": "Discord Python Hacktoberbot"}          async with aiohttp.ClientSession() as session: -            async with session.get(query_url, headers=headers) as resp: +            async with session.get(query_url, headers=REQUEST_HEADERS) as resp:                  jsonresp = await resp.json()          if "message" in jsonresp.keys(): | 
