diff options
| -rw-r--r-- | bot/exts/halloween/hacktoberstats.py | 17 | 
1 files changed, 9 insertions, 8 deletions
| diff --git a/bot/exts/halloween/hacktoberstats.py b/bot/exts/halloween/hacktoberstats.py index 50d3aaf6..b5d8591d 100644 --- a/bot/exts/halloween/hacktoberstats.py +++ b/bot/exts/halloween/hacktoberstats.py @@ -4,6 +4,7 @@ import re  from collections import Counter  from datetime import datetime, timedelta  from typing import List, Optional, Tuple, Union +from urllib.parse import quote_plus  import discord  from async_rediscache import RedisCache @@ -208,24 +209,24 @@ class HacktoberStats(commands.Cog):          None will be returned when the GitHub user was not found.          """          log.info(f"Fetching Hacktoberfest Stats for GitHub user: '{github_username}'") -        base_url = "https://api.github.com/search/issues?q=" +        base_url = "https://api.github.com/search/issues"          action_type = "pr"          is_query = "public"          not_query = "draft"          date_range = f"{CURRENT_YEAR}-09-30T10:00Z..{CURRENT_YEAR}-11-01T12:00Z"          per_page = "300" -        query_url = ( -            f"{base_url}" +        query_params = (              f"+type:{action_type}"              f"+is:{is_query}" -            f"+author:{github_username}" +            f"+author:{quote_plus(github_username)}"              f"+-is:{not_query}"              f"+created:{date_range}"              f"&per_page={per_page}"          ) -        log.debug(f"GitHub query URL generated: {query_url}") -        jsonresp = await self._fetch_url(query_url, REQUEST_HEADERS) +        log.debug(f"GitHub query parameters generated: {query_params}") + +        jsonresp = await self._fetch_url(base_url, REQUEST_HEADERS, dict(q=query_params))          if "message" in jsonresp:              # One of the parameters is invalid, short circuit for now              api_message = jsonresp["errors"][0]["message"] @@ -295,9 +296,9 @@ class HacktoberStats(commands.Cog):                  outlist.append(itemdict)          return outlist -    async def _fetch_url(self, url: str, headers: dict) -> dict: +    async def _fetch_url(self, url: str, headers: dict, params: dict) -> dict:          """Retrieve API response from URL.""" -        async with self.bot.http_session.get(url, headers=headers) as resp: +        async with self.bot.http_session.get(url, headers=headers, params=params) as resp:              return await resp.json()      @staticmethod | 
