Example #1
0
def test_get_list():
    l = courses.get_list()

    assert 6000 < len(l) < 9000
    assert isinstance(l, dict)
    assert all([isinstance(x, Slug) for x in l.keys()])
    assert l[Slug('info', 'f', '101')] == "Programmation"
Example #2
0
    def get_from_slug(cls, slug, year):
        slug = Slug.match_all(slug)

        response = cls._query_ulb(year, slug)
        if not response.ok:
            raise Exception("Error with ulb")

        soup = BeautifulSoup(response.text, "html.parser")

        table = soup.find('table', 'bordertable')
        tr_list = table('tr')

        infos = {}

        for line in tr_list:
            if len(line('td')) != 2:
                continue
            key, val = line('td')
            key = key.text.strip().strip("*").strip()
            val = val.text.strip().strip("*").strip()
            infos[key] = val

        slug = "{}-{}-{}".format(slug.domain, slug.faculty,
                                 slug.number).lower()
        return cls(slug, year, infos)
Example #3
0
def get_list():
    txt = requests.get("http://gehol.ulb.ac.be/gehol/Vue/HoraireCours.php").text
    courses = json.loads(re.search(r'<script>\s\n\svar data =(.*);\s\n', txt).groups()[0])

    ret = {}

    for course in courses:
        mnemo = course['label']
        name = course['value']

        name = name.replace("[{}]".format(mnemo), "").strip()
        slug = Slug.from_gehol(mnemo)

        ret[slug] = name

    return ret
Example #4
0
def prettify_event(course):
    course['days'] = course['Date(s)'].split(', ')
    del course['Date(s)']

    course['groups'] = course['Groupe(s)'].split(', ')
    del course['Groupe(s)']

    course['weeks'] = course['Semaine(s)'].split('; ')
    del course['Semaine(s)']

    # 'title' looks like 'Programmation [INFOF101]'
    course['name'], course['slug'] = re.match(r"^(.*)\[([A-Z]{5}\d{3,4})\]$", course['title']).groups()
    del course['title']

    course['name'] = course['name'].strip()
    course['slug'] = Slug.from_gehol(course['slug'])

    return course
Example #5
0
def get_list():
    txt = requests.get(
        "http://gehol.ulb.ac.be/gehol/Vue/HoraireCours.php").text
    courses = json.loads(
        re.search(r'<script>\s\n\svar data =(.*);\s\n', txt).groups()[0])

    ret = {}

    for course in courses:
        mnemo = course['label']
        name = course['value']

        name = name.replace("[{}]".format(mnemo), "").strip()
        slug = Slug.from_gehol(mnemo)

        ret[slug] = name

    return ret
Example #6
0
    def get_from_slug(cls, slug, year):
        slug = Slug.match_all(slug)

        response = cls._query_ulb(year, slug)
        if not response.ok:
            raise Exception("Error with ulb")

        soup = BeautifulSoup(response.text, "html.parser")

        table = soup.find('table', 'bordertable')
        tr_list = table('tr')

        infos = {}

        for line in tr_list:
            if len(line('td')) != 2:
                continue
            key, val = line('td')
            key = key.text.strip().strip("*").strip()
            val = val.text.strip().strip("*").strip()
            infos[key] = val

        slug = "{}-{}-{}".format(slug.domain, slug.faculty, slug.number).lower()
        return cls(slug, year, infos)
Example #7
0
def slug1():
    return Slug('info', 'f', '101')
Example #8
0
def test_2_digit():
    Slug('info', 'y', '56')