コード例 #1
0
ファイル: util.py プロジェクト: mathisfchx/ASTUSbot
def getWeekCalendar(calendarPath=CALENDAR_PATH, offset=0):
    """ @HBA
    compute the week calendar of a group
    :param calendarPath: path to the calendar file of the group
    :param offset: int to offset the calendar week
    :return: Table Object that can be printed
    """
    CurrentWeekday = datetime.today().isoweekday()
    WeekCalendar = {}
    for DayIndex in range(0, CurrentWeekday):
        Day = datetime.today() - timedelta(days=DayIndex) + timedelta(
            days=offset * 7)
        WeekCalendar[CurrentWeekday - DayIndex] = getCourseByDate(
            promptDate=Day.date(), calendarPath=calendarPath)
    for DayIndex in range(CurrentWeekday, 6):
        Day = datetime.today() + timedelta(
            days=DayIndex + 1 - CurrentWeekday) + timedelta(days=offset * 7)
        WeekCalendar[DayIndex + 1] = getCourseByDate(promptDate=Day.date(),
                                                     calendarPath=calendarPath)

    for DayIndex in range(1, 7):
        formattedCourses = []
        is4HourCourse = False
        for courseBeginingTime in [8, 10, 14, 16]:
            if is4HourCourse:
                is4HourCourse = False
                continue
            isChanged = False
            for course in WeekCalendar[DayIndex]:
                if course['DTSTART'].dt.hour == courseBeginingTime:
                    if course['DTEND'].dt.hour - course['DTSTART'].dt.hour == 4:
                        formattedCourses += [formatCourse(course)
                                             ] * 2  # add 4 hour course twice
                        is4HourCourse = True
                    else:
                        formattedCourses.append(formatCourse(course))
                    isChanged = True
                    break
            if not isChanged:
                formattedCourses.append("🥳")
        WeekCalendar[DayIndex] = formattedCourses
        # if len(WeekCalendar[DayIndex]) < 4:
        #     while len(WeekCalendar[DayIndex]) != 4:
        #         WeekCalendar[DayIndex].append("🥳")

    Calendar = PrettyTable()
    for DayIndex in range(1, 6):
        Calendar.add_column(WEEKDAYS[DayIndex], WeekCalendar[DayIndex])

    return Calendar
コード例 #2
0
def getWeekCalendar(calendarPath=CALENDAR_PATH):
    CurrentWeekday = datetime.today().isoweekday()
    WeekCalendar = {}
    for DayIndex in range(0, CurrentWeekday):
        Day = datetime.today() - timedelta(days=DayIndex)
        WeekCalendar[CurrentWeekday - DayIndex] = getCourseByDate(date=Day.date(), calendarPath=calendarPath)
    for DayIndex in range(CurrentWeekday, 6):
        Day = datetime.today() + timedelta(days=DayIndex + 1 - CurrentWeekday)
        WeekCalendar[DayIndex + 1] = getCourseByDate(date=Day.date(), calendarPath=calendarPath)

    for DayIndex in range(1, 7):
        formattedCourses = []
        is4HourCourse = False
        for courseBeginingTime in [8, 10, 14, 16]:
            if is4HourCourse:
                is4HourCourse= False
                continue
            isChanged = False
            for course in WeekCalendar[DayIndex]:
                if course['DTSTART'].dt.hour == courseBeginingTime:
                    if course['DTEND'].dt.hour - course['DTSTART'].dt.hour == 4:
                        formattedCourses += [formatCourse(course)] * 2  # add 4 hour course twice
                        is4HourCourse = True
                    else:
                        formattedCourses.append(formatCourse(course))
                    isChanged = True
                    break
            if not isChanged:
                formattedCourses.append("🥳")
        WeekCalendar[DayIndex] = formattedCourses
        # if len(WeekCalendar[DayIndex]) < 4:
        #     while len(WeekCalendar[DayIndex]) != 4:
        #         WeekCalendar[DayIndex].append("🥳")

    Calendar = PrettyTable()
    for DayIndex in range(1, 6):
        Calendar.add_column(WEEKDAYS[DayIndex], WeekCalendar[DayIndex])

    return Calendar