aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar D0rs4n <[email protected]>2021-08-07 22:19:29 +0200
committerGravatar D0rs4n <[email protected]>2021-08-07 22:22:12 +0200
commit7adb1819668cd95e09c38bb98374b322fad0848d (patch)
tree27708d1981e7779996c6ebf8c6cb01afbb35df1b
parentUse quote_plus instead of quote in the Githubinfo Cog (diff)
Update Hacktoberstats' get_october_prs function to use aiohttps get params
-rw-r--r--bot/exts/halloween/hacktoberstats.py17
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