Skip to content

Commit

Permalink
fix: course helper method template/formatting (#620)
Browse files Browse the repository at this point in the history
* fix: course helper method template/formatting

* lint
  • Loading branch information
davidlougheed authored Sep 7, 2024
1 parent 5af4c7a commit 3ceee03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions canary/cogs/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async def course(self, ctx: commands.Context, *, query: str):
return

search_term = re.sub(r"\s+", "", f"{result.group(1)}-{result.group(2)}")
url = self.bot.config.course_tpl.format(self.bot.config.course_year_range, search_term)
url = self.bot.config.course_tpl.format(course_year_range=self.bot.config.course_year_range, course=search_term)
r = await fetch(url, "content")
soup = BeautifulSoup(r, "lxml")

Expand Down Expand Up @@ -465,7 +465,12 @@ async def search(self, ctx: commands.Context, *, query: str):

while pagenum < pagelimit:
r = await fetch(
self.bot.config.course_search_tpl.format(self.bot.config.course_year_range, keyword, pagenum), "content"
self.bot.config.course_search_tpl.format(
course_year_range=self.bot.config.course_year_range,
search=keyword,
page=pagenum,
),
"content",
)
soup = BeautifulSoup(r, "lxml")
found = soup.find_all("div", {"class": "views-row"})
Expand Down
6 changes: 3 additions & 3 deletions canary/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ class Config(BaseSettings):

# Helpers configuration
course_year_range: str = "2024-2025"
course_tpl: str = "http://www.mcgill.ca/study/{course_year_range}/courses/{}"
course_tpl: str = "http://www.mcgill.ca/study/{course_year_range}/courses/{course}"
course_search_tpl: str = (
"http://www.mcgill.ca/study/{course_year_range}/courses/search?search_api_views_fulltext={}"
"http://www.mcgill.ca/study/{course_year_range}/courses/search?search_api_views_fulltext={search}"
"&sort_by=field_subject_code"
"&page={}"
"&page={page}"
)
gc_weather_url: str = "https://dd.weather.gc.ca/citypage_weather/xml/QC/s0000635_e.xml"
gc_weather_alert_url: str = "https://weather.gc.ca/warnings/report_e.html?qc67"
Expand Down

0 comments on commit 3ceee03

Please sign in to comment.