コード例 #1
0
ファイル: schedule.py プロジェクト: asaf-kali/coursist
def del_user_schedule_groups(user, group_ids):
    log.info(
        f"del_user_schedule_group for user {wrap(user)} with group_ids {wrap(group_ids)}"
    )
    if user.is_anonymous:
        log.warning("del_user_schedule_group called but user is_anonymous")
        raise UserNotLoggedInError()
    ClassSchedule.objects.filter(user=user, group_id__in=group_ids).delete()
    log.info(f"del_user_schedule_group deleted {wrap(group_ids)}")
コード例 #2
0
def create_course_class(group: ClassGroup, i: int, raw_group: dict,
                        raw_semester: str, teachers: List[str]):
    teacher = parse_teacher(teachers[i])
    try:
        semester = parse_lesson_semester(raw_semester).value
    except Exception as e:
        semester = group.occurrence.semester
    try:
        day = parse_day_of_week(raw_group["day"][i]).value
    except Exception as e:
        log.warning(f"Skipping day: {e}")
        day = DayOfWeek.UNDEFINED.value
    try:
        start_time, end_time = parse_times(raw_group["hour"][i])
    except Exception as e:
        log.warning(f"Skipping times: {e}")
        start_time, end_time = None, None
    try:
        hall = parse_hall(raw_group["hall"][i])
    except Exception as e:
        log.warning(f"Skipping hall: {e}")
        hall = None
    course_class, created = CourseClass.objects.get_or_create(
        group=group,
        teacher=teacher,
        semester=semester,
        day=day,
        start_time=start_time,
        end_time=end_time,
        hall=hall,
    )
    if created:
        log.info(f"Class {course_class.id} created")
コード例 #3
0
    def extract_data_from_shnaton(year: int, course_id: int) -> Optional[dict]:
        html = ShnatonParser.get_course_html(year, course_id)
        source = BeautifulSoup(html, "html.parser")

        if len(source.find_all(class_="courseTD")) == 0:
            log.warning(f"Skipping course {course_id} because of bad html")
            # course not found
            return None

        course = dict()
        # parse faculty and school
        ShnatonParser.parse_faculty(source, course)
        if "faculty" not in course or "school" not in course:
            log.warning(f"Skipping course {course_id} because of bad html")
            # course faculty / school not found
            return None

        # parse general course info
        ShnatonParser.parse_general_course_info(source, year, course)

        # parse lessons info
        ShnatonParser.parse_lessons(source, course)

        return course
コード例 #4
0
def create_course_class(group: ClassGroup, i: int, raw_group: dict,
                        raw_semester: str, teacher: Teacher):
    try:
        semester = parse_lesson_semester(raw_semester).value
    except Exception:
        semester = group.occurrence.semester
    try:
        day = parse_day_of_week(raw_group["day"][i]).value
    except Exception as e:
        log.warning(f"Skipping day: {e}")
        day = DayOfWeek.UNDEFINED.value
    try:
        start_time, end_time = parse_times(raw_group["hour"][i])
    except Exception as e:
        log.warning(f"Skipping times: {e}")
        start_time, end_time = None, None
    try:
        hall = parse_hall(raw_group["hall"][i])
    except Exception as e:
        log.warning(f"Skipping hall: {e}")
        hall = None
    special_occurrence = None
    notes = None
    if len(raw_group["special_occurrences"]) > i:
        raw = raw_group["special_occurrences"][i]
        try:
            special_occurrence = datetime.strptime(raw, "%d/%m/%y").date()
        except Exception as e:
            log.warning(f"Skipping special occurrence: {e}")
            notes = raw
    course_class, created = CourseClass.objects.get_or_create(
        group=group,
        semester=semester,
        day=day,
        start_time=start_time,
        end_time=end_time,
        hall=hall,
        teacher=teacher,
        special_occurrence=special_occurrence,
    )
    if created:
        log.info(f"Class {course_class.id} created")
    course_class.notes = notes
    course_class.save()
    return course_class
コード例 #5
0
 def create_course_class(group: ClassGroup, i, raw_group, raw_semester,
                         teachers):
     # TODO: This does not handle 2 teachers for 1 group case (course 1920)
     teacher = parse_teacher(teachers[i])
     try:
         semester = parse_lesson_semester(raw_semester).value
     except Exception as e:
         semester = group.occurrence.semester
     try:
         day = parse_day_of_week(raw_group["day"][i]).value
     except Exception as e:
         log.warning(
             f"Skipping day for course {group.occurrence.course.course_number}: {e}"
         )
         day = DayOfWeek.UNDEFINED.value
     try:
         start_time, end_time = parse_times(raw_group["hour"][i])
     except Exception as e:
         log.warning(
             f"Skipping times for course {group.occurrence.course.course_number}: {e}"
         )
         start_time, end_time = None, None
     try:
         hall = parse_hall(raw_group["hall"][i])
     except Exception as e:
         log.warning(
             f"Skipping hall for course {group.occurrence.course.course_number}: {e}"
         )
         hall = None
     course_class, created = CourseClass.objects.get_or_create(
         group=group,
         teacher=teacher,
         semester=semester,
         day=day,
         start_time=start_time,
         end_time=end_time,
         hall=hall,
     )
     if created:
         log.info(f"Class {course_class.id} created")