From 8e22ce526e99dc0621219b6fe06cffd2ea16e2b0 Mon Sep 17 00:00:00 2001 From: dipernalz Date: Fri, 18 Mar 2022 13:22:00 -0400 Subject: [PATCH] Bug fixes --- setup.cfg | 2 +- src/vtt/__init__.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 96e6a05..a3273ad 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = vt-timetable -version = 0.2.5 +version = 0.2.6 author = Leo DiPerna author_email = dipernalz@vt.edu description = A python module for scraping the Virginia Tech Timetable of Classes. diff --git a/src/vtt/__init__.py b/src/vtt/__init__.py index e647ed1..beddb2d 100644 --- a/src/vtt/__init__.py +++ b/src/vtt/__init__.py @@ -9,6 +9,7 @@ possible to check which search parameters are valid. """ +from collections import defaultdict from enum import Enum import re from typing import Dict, List, Set, Tuple @@ -179,23 +180,24 @@ def __init__(self, year: str, semester: Semester, name = timetable_data[2] section_type = self._section_type_dct[ - 'O' if timetable_data[3] == 'ONLINE COURSE' else + 'O' if re.match(r'ONLINE COURSE', timetable_data[3]) else re.match(r'[LBICR]', timetable_data[3]).group(0)] modality = (self._modality_dct[timetable_data[4]] if timetable_data[4] in self._modality_dct else None) - class_dct = {} + class_dct = defaultdict(set) for day in [self._day_dct[d] for d in timetable_data[8].split()]: if day == Day.ARRANGED: continue - class_dct[day] = (timetable_data[9], timetable_data[10], - timetable_data[11]) + class_dct[day].add((timetable_data[9], timetable_data[10], + timetable_data[11])) if (extra_class_data is not None and extra_class_data[4] == '* Additional Times *'): for day in [self._day_dct[d] for d in extra_class_data[8].split()]: - class_dct[day] = (extra_class_data[9], extra_class_data[10], - extra_class_data[11]) + class_dct[day].add((extra_class_data[9], extra_class_data[10], + extra_class_data[11])) + class_dct = dict(class_dct) self._course_data = {'year': year, 'semester': semester, 'crn': timetable_data[0][:5], @@ -246,7 +248,7 @@ def get_capacity(self) -> str: def get_professor(self) -> str: return self._course_data['professor'] - def get_schedule(self) -> Dict: + def get_schedule(self) -> Dict[Day, Set[Tuple[str, str, str]]]: return self._course_data['schedule'] def has_open_spots(self) -> bool: