Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course ECP Command #171

Merged
merged 13 commits into from
Nov 2, 2023
Prev Previous commit
Next Next commit
Course ECP now considers the year, semester, campus and mode input
Need to format the embedded and allow it to take in multiple courses
  • Loading branch information
ew-b committed Oct 24, 2023
commit eb4b5eec03058476c148a230f75c01ebbb54f34e
31 changes: 27 additions & 4 deletions uqcsbot/course_ecp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ async def courseecp(
await interaction.response.defer(thinking=True)

offering = Offering(semester=semester, campus=campus, mode=mode)

try:
course_url = get_course_profile_url(course_code, offering)
course_url = get_course_profile_url(course_code, offering, year)
except HttpException as exception:
logging.warning(
f"Received a HTTP response code {exception.status_code}. Error information: {exception.message}"
ew-b marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -61,15 +61,38 @@ async def courseecp(
await interaction.edit_original_response(content=exception.message)
return

# Below needs to account for the year, semester, mode and campus offerings,
# Currently it just defaults to current offering.
embed = discord.Embed(
title=f"Course ECP for {course_code.upper()}",
url=course_url,
# Make below considerate of offering.
# description=f"[{course_code.upper()}]({course_url})",
)

if semester:
embed.add_field(
name="Semester",
value = str(semester),
inline=False,
)
if year:
embed.add_field(
name="Year",
value = str(year),
inline=False,
)
if campus:
embed.add_field(
name="Campus",
value = str(campus),
inline=False,
)
if mode:
embed.add_field(
name="Delivery mode",
value = str(mode),
inline=False,
)

if not course_url:
await interaction.edit_original_response(
content=f"No ECP could be found for {course_code}. The {course_code}'s ECP might not be available."
Expand Down
6 changes: 3 additions & 3 deletions uqcsbot/utils/uq_course_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ def get_uq_request(


def get_course_profile_url(
course_name: str, offering: Optional[Offering] = None, year: Optional[int]
course_name: str, offering: Optional[Offering] = None, year: Optional[int] = None,
) -> str:
"""
Returns the URL to the course profile (ECP) for the given course for a given offering.
If no offering or year are given, the first course profile on the course page will be returned.
"""
course_url = BASE_COURSE_URL + course_name
if offering:
course_url += "&" + OFFERING_PARAMETER + offering.get_offering_code()
course_url += "&" + OFFERING_PARAMETER + "=" + offering.get_offering_code()
if year:
course_url += "&" + YEAR_PARAMETER + year
course_url += "&" + YEAR_PARAMETER + "=" + str(year)

http_response = get_uq_request(course_url)
if http_response.status_code != requests.codes.ok:
Expand Down