예제 #1
0
def getLessons(certificate, day):
    client = Vulcan(certificate)
    LastWeek = getLastWeek()
    Lessons = []
    if (day == "pon"):
        for lesson in client.get_lessons(LastWeek[0]):
            Lessons.append(
                str(lesson.time.from_)[:-3] + "-" + str(lesson.time.to)[:-3])
            Lessons.append(str(lesson.subject.name))
            if (str(lesson.group) != "None"):
                Lessons.append(
                    str(lesson.room) + " Grupa: " + str(lesson.group))
            else:
                Lessons.append(str(lesson.room))
        return Lessons
    elif (day == "wt"):
        for lesson in client.get_lessons(LastWeek[1]):
            Lessons.append(
                str(lesson.time.from_)[:-3] + "-" + str(lesson.time.to)[:-3])
            Lessons.append(str(lesson.subject.name))
            if (str(lesson.group) != "None"):
                Lessons.append(
                    str(lesson.room) + " Grupa: " + str(lesson.group))
            else:
                Lessons.append(str(lesson.room))
        return Lessons
    elif (day == "sr"):
        for lesson in client.get_lessons(LastWeek[2]):
            Lessons.append(
                str(lesson.time.from_)[:-3] + "-" + str(lesson.time.to)[:-3])
            Lessons.append(str(lesson.subject.name))
            if (str(lesson.group) != "None"):
                Lessons.append(
                    str(lesson.room) + " Grupa: " + str(lesson.group))
            else:
                Lessons.append(str(lesson.room))
        return Lessons
    elif (day == "czw"):
        for lesson in client.get_lessons(LastWeek[3]):
            Lessons.append(
                str(lesson.time.from_)[:-3] + "-" + str(lesson.time.to)[:-3])
            Lessons.append(str(lesson.subject.name))
            if (str(lesson.group) != "None"):
                Lessons.append(
                    str(lesson.room) + " Grupa: " + str(lesson.group))
            else:
                Lessons.append(str(lesson.room))
        return Lessons
    elif (day == "pt"):
        for lesson in client.get_lessons(LastWeek[4]):
            Lessons.append(
                str(lesson.time.from_)[:-3] + "-" + str(lesson.time.to)[:-3])
            Lessons.append(str(lesson.subject.name))
            if (str(lesson.group) != "None"):
                Lessons.append(
                    str(lesson.room) + " Grupa: " + str(lesson.group))
            else:
                Lessons.append(str(lesson.room))
        return Lessons
예제 #2
0
def prepare_plan():
    #this function prepares txt files with plans for days of the week inside | no arguments, no returns

    if os.path.isdir("plan"):
        for file in os.listdir("plan"):
            os.remove(f"plan/{file}")
        os.rmdir("plan")

    if not os.path.isdir("plan"):
        os.makedirs("plan")

    #prepare connection with Vulcan account
    with open("cert.json") as f:
        certificate = json.load(f)

    client = Vulcan(certificate)

    last_num = 0
    data = ""
    day_name = ""

    for i in range(7):

        free = True
        data = date.today() + timedelta(i)

        if data.weekday() == 0: day_name = "poniedzialek"
        if data.weekday() == 1: day_name = "wtorek"
        if data.weekday() == 2: day_name = "sroda"
        if data.weekday() == 3: day_name = "czwartek"
        if data.weekday() == 4: day_name = "piatek"
        if data.weekday() in (5, 6): continue

        file = open(f"plan/{day_name}.txt", "w+")
        file.write(f"Plan na {day_name}:")

        for lesson in client.get_lessons(data):

            free = False

            if ((last_num == 0) and (lesson.number > 1)):
                last_num = lesson.number - 1

            lesson_name = change_this(lesson.subject.name)
            teacher_name = change_this(lesson.teacher.short)

            if lesson.number != last_num:
                file.write(
                    f"\n{lesson.number}. {lesson_name} ({teacher_name})")
                last_num += 1

            else:
                file.write(f" / {lesson_name} ({teacher_name})")

        last_num = 0

        file.close()

        if free:
            new_file = open(f"plan/{day_name}.txt", "w")
            new_file.write(f"Brak lekcji na {day_name}!!! WOLNE!!!")
            new_file.close()
예제 #3
0
    else:
        print("No cert found!")
        exit()
    
vulcan = Vulcan(cert)

while True:
    dates = []
    for x in range(30):
        dates.append(datetime.date.today() + datetime.timedelta(days=x))

    exams = []
    for date in dates:
        for exam in vulcan.get_exams(date=date):
            lessons = []
            for lesson in vulcan.get_lessons(date=date):
                if exam.subject == lesson.subject:
                    lessons.append(lesson)
            if len(lessons) > 0:
                exams.append([exam, lessons])

    events = []
    for exam in exams:
        if len(exam[1]) > 0:
            events.append(caldav.createExamEvent(exam[0], exam[1][0]))

    homeworks = []
    for date in dates:
        for homework in vulcan.get_homework(date=date):
            lessons = []
            for lesson in vulcan.get_lessons(date=date):