Skip to content

Commit

Permalink
Fix KeyError when there's no room_name in the JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
mario872 committed May 7, 2024
1 parent b284e99 commit d5e8abc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
5 changes: 1 addition & 4 deletions sentralify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ def sentralify(config: dict, timetable: bool = True, notices: bool = True, calen

start = time.time() # So that we can know how long it took to scrape the Sentral data

try:
p = sync_playwright().start() # Start a playwright instance
except playwright._impl._errors.Error:
pass
p = sync_playwright().start() # Start a playwright instance

# Initialise the generators and scrapers
Sentral = generators
Expand Down
5 changes: 4 additions & 1 deletion sentralify/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ def generate_timetable(data: list):
if current_day_data['period'][period]['lessons'] != []: # If it's a period without a lesson, then there's nothing in the lesson parameter
timetable[timetable_day]['periods'][period]['full_name'] = current_day_data['period'][period]['lessons'][0]['subject_name']
timetable[timetable_day]['periods'][period]['name'] = current_day_data['period'][period]['lessons'][0]['lesson_class_name']
timetable[timetable_day]['periods'][period]['room'] = current_day_data['period'][period]['lessons'][0]['room_name']
try:
timetable[timetable_day]['periods'][period]['room'] = current_day_data['period'][period]['lessons'][0]['room_name']
except KeyError: # If there's not set it to None:
timetable[timetable_day]['periods'][period]['room'] = None
timetable[timetable_day]['periods'][period]['border_colour'] = current_day_data['period'][period]['lessons'][0]['class_border_colour']
timetable[timetable_day]['periods'][period]['background_colour'] = current_day_data['period'][period]['lessons'][0]['class_background_colour']
try: # This checks that there is a teacher during the lesson
Expand Down

0 comments on commit d5e8abc

Please sign in to comment.