Skip to content

Commit

Permalink
Black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ew-b committed Nov 2, 2023
1 parent a461273 commit c1ceb09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 13 additions & 12 deletions uqcsbot/course_ecp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from uqcsbot.yelling import yelling_exemptor


class CourseECP(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
Expand All @@ -29,10 +30,7 @@ def __init__(self, bot: commands.Bot):
campus="The campus the course is held at. Defaults to St Lucia. Defaults to St Lucia. Note that many external courses are 'hosted' at St Lucia.",
mode="The mode of the course. Defaults to Internal.",
)
@yelling_exemptor(
input_args=["course1, course2, course3, course4"]
)

@yelling_exemptor(input_args=["course1, course2, course3, course4"])
async def courseecp(
self,
interaction: discord.Interaction,
Expand All @@ -53,36 +51,38 @@ async def courseecp(

possible_courses = [course1, course2, course3, course4]
course_names = [c.upper() for c in possible_courses if c != None]
course_name_urls: dict[str,str] = {}
course_name_urls: dict[str, str] = {}
offering = Offering(semester=semester, campus=campus, mode=mode)

try:
for course in course_names:
course_name_urls.update({course: get_course_profile_url(course, offering, year)})
course_name_urls.update(
{course: get_course_profile_url(course, offering, year)}
)
except HttpException as exception:
logging.warning(
f"Received a HTTP response code {exception.status_code} when trying find the course url using get_course_profile_url in course_ecp.py . Error information: {exception.message}"
)
)
await interaction.edit_original_response(
content=f"Could not contact UQ, please try again."
)
return
except (CourseNotFoundException, ProfileNotFoundException) as exception:
except (CourseNotFoundException, ProfileNotFoundException) as exception:
await interaction.edit_original_response(content=exception.message)
return

# If year is none assign it the current year
if not year:
year = datetime.today().year

# If semester is none assign it the current estimated semester
if not semester:
semester = Offering.estimate_current_semester()

# Create the embedded message with the course names and details
embed = discord.Embed(
title=f"Course ECP: {', '.join(course_names)}",
description=f"For Semester {semester} {year}, {mode}, {campus}"
description=f"For Semester {semester} {year}, {mode}, {campus}",
)

# Add the ECP urls to the embedded message
Expand All @@ -105,5 +105,6 @@ async def courseecp(
await interaction.edit_original_response(embed=embed)
return


async def setup(bot: commands.Bot):
await bot.add_cog(CourseECP(bot))
4 changes: 3 additions & 1 deletion uqcsbot/utils/uq_course_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ def get_uq_request(


def get_course_profile_url(
course_name: str, offering: Optional[Offering] = None, year: Optional[int] = None,
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.
Expand Down

0 comments on commit c1ceb09

Please sign in to comment.