<commit_before>import json
from .course import Course 
from .coursetime import courseTime 
from datetime import datetime 

class CourseManager():
    """A class for managing courses.
    
    Attributes:
        courses (list): A list of all course objects being handled by the session.
        saved (bool): Whether or not the course information is consistent with
                      the file on the disk.
        last_course_id (int): The greatest course id in use by a Course object.
    """
    def __init__(self, store=None):
        """Initialize a CourseManager.

        Arguments:
            store (Gtk.ListStore): a store to append data into.
        """
        self.store = store 
        
        self.courses = {}
        self.ge_map = {}        
        self.user = {
                'year': 1
                }
        
        today = datetime.today()
        
        fall = datetime(today.year, 9, 15)
        winter = datetime(today.year, 1, 1)
        spring = datetime(today.year, 3, 31)
        summer = datetime(today.year, 6, 15)

        if fall <= today <= datetime(today.year, 12, 31):
            self.quarter = 0
        elif winter <= today < spring:
            self.quarter = 1
        elif spring <= today < summer:
            self.quarter = 2
        else:
            self.quarter = 3

        self.saved = True
        self.last_course_id = 0
        


    def load_file(self, filename):
        """Load a file into the course manager.

        Arguments:
            filename (str): The path to the JSON file 
                            containing the course information.

        Returns:
            1 if successful, 0 otherwise.
        """
        with open(filename, 'r') as jsonfile:
            try:
                courses = json.loads(jsonfile.read())
            except ValueError: 
                return 0

        file_courses = courses
        course_id = 0
        course_ids = []

        cs = file_courses['courses'] 
        #tmp_cs = file_courses['courses'] 
        
        """ Old compatibility code
        if isinstance(tmp_cs, list):
            cs = {}
            for course_object in tmp_cs:
                object_id = course_object.pop('course_id')
                cs[object_id] = course_object

        elif isinstance(tmp_cs, dict): 
            cs = tmp_cs 
        else:
            raise Exception("Invalid course object!")
            return 0
        """

        for course_id, course in cs.items():
            course_id = int(course_id)
            if isinstance(course['prereqs'], str):
                course['prereqs'] = [x.strip() for x in 
                    course['prereqs'].split(',')]

            if 'ge_type' not in course:
                course['ge_type'] = None

            course['time'] = courseTime(int(course['time'][0]), course['time'][1])

            self.courses[course_id] = course

            if self.store:
                self.store.append([
                    course['catalog'], 
                    str(
                        str(course['time'][0]) + 
                        ', ' + 
                        course['time'][1]
                        ), <commit_msg>GE type now goes in a list (in case there are multiple types)<commit_after>import json
from .course import Course 
from .coursetime import courseTime 
from datetime import datetime 

class CourseManager():
    """A class for managing courses.
    
    Attributes:
        courses (list): A list of all course objects being handled by the session.
        saved (bool): Whether or not the course information is consistent with
                      the file on the disk.
        last_course_id (int): The greatest course id in use by a Course object.
    """
    def __init__(self, store=None):
        """Initialize a CourseManager.

        Arguments:
            store (Gtk.ListStore): a store to append data into.
        """
        self.store = store 
        
        self.courses = {}
        self.ge_map = {}        
        self.user = {
                'year': 1
                }
        
        today = datetime.today()
        
        fall = datetime(today.year, 9, 15)
        winter = datetime(today.year, 1, 1)
        spring = datetime(today.year, 3, 31)
        summer = datetime(today.year, 6, 15)

        if fall <= today <= datetime(today.year, 12, 31):
            self.quarter = 0
        elif winter <= today < spring:
            self.quarter = 1
        elif spring <= today < summer:
            self.quarter = 2
        else:
            self.quarter = 3

        self.saved = True
        self.last_course_id = 0
        


    def load_file(self, filename):
        """Load a file into the course manager.

        Arguments:
            filename (str): The path to the JSON file 
                            containing the course information.

        Returns:
            1 if successful, 0 otherwise.
        """
        with open(filename, 'r') as jsonfile:
            try:
                courses = json.loads(jsonfile.read())
            except ValueError: 
                return 0

        file_courses = courses
        course_id = 0
        course_ids = []

        cs = file_courses['courses'] 
        #tmp_cs = file_courses['courses'] 
        
        """ Old compatibility code
        if isinstance(tmp_cs, list):
            cs = {}
            for course_object in tmp_cs:
                object_id = course_object.pop('course_id')
                cs[object_id] = course_object

        elif isinstance(tmp_cs, dict): 
            cs = tmp_cs 
        else:
            raise Exception("Invalid course object!")
            return 0
        """

        for course_id, course in cs.items():
            course_id = int(course_id)
            if isinstance(course['prereqs'], str):
                course['prereqs'] = [x.strip() for x in 
                    course['prereqs'].split(',')]

            if 'ge_type' not in course:
                course['ge_type'] = [None]
            elif isinstance(course['ge_type'], str):
                course['ge_type'] = [course['ge_type']]

            course['time'] = courseTime(int(course['time'][0]), course['time'][1])

            self.courses[course_id] = course

            if self.store:
                self.store.append([
                    course['catalog'], 
                    str(
                        str(course['time'][0]) + 
                        ', ' + 
                        course['time'][1]
                        ), 
{'fraction_non_alphanumeric': 0.09820744599356519, 'fraction_numerical': 0.009192584648383637, 'mean_word_length': 1.4186735828084476, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5376431', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1652, 'n_words': 501}