Esempio n. 1
0
def parse(module_id, name, school):
    url = URL_START + module_id + URL_END
    data = utils.download_string(url)
    soup = BeautifulSoup(data, "lxml")
    modules = []
    events = []
    weekday_tables = soup.findAll("table", attrs={"cellpadding": "2%"})
    for i in range(0, 5):
        rows = weekday_tables[i].findAll("tr")
        if len(rows) > 0:
            for row in rows[1:]:
                cols = row.findAll("td")
                event = {"name": cols[1].get_text(strip=True), "type": cols[2].get_text(strip=True), "day": DAYS[i],
                         "startTime": utils.format_time(cols[5].get_text(strip=True)),
                         "endTime": utils.format_time(cols[6].get_text(strip=True))}
                room_code = cols[8].get_text(strip=True).split(",")[0]
                event["roomCode"] = room_code
                event["roomDescription"] = utils.room_code_to_desc(room_code)
                event["staff"] = utils.get_event_staff(cols[11].get_text(strip=True).split(",")[0], school)
                event["weeks"] = utils.weeks_to_list(cols[12].get_text(strip=True))
                module_codes = get_module_codes(cols[0].get_text(strip=True).split("/"))
                modules.append(module_codes[0])
                for code in module_codes:
                    module_event = event.copy()
                    module_event["code"] = code
                    events.append(module_event)
    modules = utils.remove_dupes(modules)
    events = utils.events_to_modules(events, modules, school)
    for event in events:
        utils.update_events(event)
    course = {"_id": module_id, "name": name, "school": school, "modules": modules}
    utils.update_course(course)
Esempio n. 2
0
def parse():
    print("Downloading zones data...")
    data = utils.download_string(URL)
    soup = BeautifulSoup(data, "lxml")
    tables = soup.findAll("table")
    tables = tables[:-2]
    for table in tables:
        rows = table.findAll("tr")
        for row in rows[1:]:
            cols = row.findAll("td")
            code = utils.trim_strings(cols[0].text)
            code = code.rsplit(" ", 1)[0]
            name = utils.trim_strings(cols[1].text)
            name = name[name.startswith("The ") and len("The "):]
            zone = {"code": code, "building": name, "campus": get_campus(code)}
            utils.update_zone(zone)