def readFile(self):
        result = []
        try:
            f = open(self.__fileName, "r")
            line = f.readline().strip()
            while len(line) > 0:
                line = line.split(";")
                result.append(Discipline(int(line[0]), line[1]))
                line = f.readline().strip()
            f.close()
        except IOError as e:

            print("An error occured - " + str(e))
            raise e

        return result
Example #2
0
 def redo(self):
     self.index += 1
     elem = self.__redoList[self.index]
     if elem[0] == "AddStudent":
         self._controller.addStudent(
             Student(elem[1].getId(), elem[1].getName()))
     elif elem[0] == "AddDiscipline":
         self._controllerD.addDiscipline(
             Discipline(elem[1].getId(), elem[1].getName()))
     elif elem[0] == "removeStudent":
         self._controller.remove(elem[1].getId())
     elif elem[0] == "removeDiscipline":
         self._controllerD.remove(elem[1].getId())
     elif elem[0] == "UpdateStudent":
         self._controller.update(elem[1].getId(), elem[1].getName())
     elif elem[0] == "UpdateDiscipline":
         self._controllerD.update(elem[1].getId(), elem[1].getName())
def read(graph, login, password):
    phantom = webdriver.PhantomJS()
    phantom.get("https://qacademico.ifce.edu.br/qacademico/index.asp?t=1001")

    form = phantom.find_element_by_id("txtLogin")
    form.send_keys(login, Keys.TAB, password)
    phantom.find_element_by_id("btnOk").click()

    phantom.get("https://qacademico.ifce.edu.br/qacademico/index.asp?t=2032")

    regexp_code_course = re.compile(r"\(\d{5}(\d{5})")
    code_course = regexp_code_course.search(
        phantom.find_elements_by_css_selector('[face="Verdana, Arial, Helvetica, sans-serif"]')[1].text.strip()
    ).groups()[0]
    select_course_grid(graph, "ifce", code_course)

    def get_element_set_semester_year():
        return phantom.find_element_by_id("cmbanos")

    def get_element_set_semester_period():
        return phantom.find_element_by_id("cmbperiodos")

    total_semester_year = len(get_element_set_semester_year().find_elements_by_tag_name("option"))
    total_semester_period = len(get_element_set_semester_period().find_elements_by_tag_name("option"))

    for current_semester_year in range(total_semester_year):
        for current_semester_period in range(total_semester_period):
            get_element_set_semester_year().find_elements_by_tag_name("option")[::-1][current_semester_year].click()
            get_element_set_semester_period().find_elements_by_tag_name("option")[::-1][current_semester_period].click()
            phantom.find_element_by_id("Exibir").click()

            for i in phantom.find_elements_by_css_selector("tbody > .conteudoTexto "):
                matter_name = i.find_elements_by_tag_name("td")[0].text.title()
                matter_status = i.find_elements_by_tag_name("td")[13].text.title()
                if matter_status == "Aprovado":
                    Discipline.get_object(matter_name).set_status(DisciplineStatus.passado)
                elif matter_status == "Cursando":
                    Discipline.get_object(matter_name).set_status(DisciplineStatus.cursando)
                elif matter_status == "Reprovado":
                    Discipline.get_object(matter_name).set_status(DisciplineStatus.reprovado)
def handle_client(client):  # Takes client socket as argument.
    """Handles a single client connection."""

    f = open("server/data/list.txt", encoding="utf8")  # файл со списком учеников и администраторов
    students = []  # список студентов
    admins = []  # список админов
    text = f.read().splitlines()
    for line in text:
        spl = line.split("*")
        if spl[3] == "admin":
            adm = Administrator()
            adm.set_surname(spl[0])
            adm.set_name(spl[1])
            adm.set_patronym(spl[2])
            adm.set_password(spl[4])
            admins.append(adm)
        else:
            stud = Student()
            stud.set_surname(spl[0])
            stud.set_name(spl[1])
            stud.set_patronym(spl[2])
            stud.set_login(spl[3])
            stud.set_password(spl[4])
            stud.set_course(int(spl[5]))
            stud.set_group(spl[6])
            stud.set_subgroup(int(spl[7]))
            students.append(stud)
    f.close()

    g = open("server/data/disciplines.txt", encoding="utf8")  # файл со списком дисциплин
    disciplines = []
    text = g.read().splitlines()
    for line in text:
        spl = line.split("*")
        subj = Discipline()
        subj.set_name(spl[0])
        subj.set_course(spl[1])
        subj.set_credits(spl[2])
        subj.set_vedomost(spl[3])
        disciplines.append(subj)
    g.close()

    flag = "0"
    while flag == "0":
        login = client.recv(1024).decode("utf8")
        password = client.recv(1024).decode("utf8")
        for stud in students + admins:
            if stud.get_login() == login and stud.get_password() == password:
                client.send(bytes("1", "utf8"))  # логин и пароль верны
                flag = "1"
                user = stud.get_surname()
                break
        if flag == "0":
            client.send(bytes("0", "utf8"))

    msg = client.recv(1024).decode("utf8")  # получаем код продвинутого\упрощенного меню

    if msg == "1":  # продвинутое меню для администратора
        while True:
            msg1 = client.recv(1024).decode("utf8")
            if msg1 == "5":  # внести изменения в учетную запись
                surname = client.recv(1024).decode("utf8")
                flag = "0"
                for stud in students:
                    if stud.get_surname() == surname:
                        flag = "1"
                        break
                client.send(bytes(flag, "utf-8"))
                if flag == "1":
                    z = client.recv(1024).decode("utf8")
                    if z == "1":  # меняем фамилию
                        new_surname = client.recv(1024).decode("utf8")
                        stud.set_surname(new_surname)
                        new_login = translit(stud.get_name()[0] + stud.get_patronym()[0] + new_surname)
                        stud.set_login(new_login)
                        client.send(bytes("Фамилия и логин изменены", "utf8"))
                        # меняем старую фамилию в ведомостях
                        for subj in disciplines:
                            m = subj.find_mark(surname)
                            f = open(subj.get_vedomost(), encoding="utf8")
                            text = f.read().splitlines()
                            new_lines = []
                            for line in text:
                                if surname in line:
                                    new_lines.append(new_surname + " " + m)
                                else:
                                    new_lines.append(line)
                            f.close()
                            f = open(subj.get_vedomost(), "w", encoding="utf8")
                            for line in new_lines:
                                f.write("%s\n" % line)
                            f.close()

                    elif z == "2":  # имя
                        new_name = client.recv(1024).decode("utf8")
                        stud.set_name(new_name)
                        new_login = translit(new_name[0] + stud.get_patronym()[0] + stud.get_surname())
                        stud.set_login(new_login)
                        client.send(bytes("Имя и логин изменены", "utf8"))
                    elif z == "3":
                        new_patronym = client.recv(1024).decode("utf8")
                        stud.set_patronym(new_patronym)
                        new_login = translit(stud.get_name()[0] + new_patronym[0] + stud.get_surname())
                        stud.set_login(new_login)
                        client.send(bytes("Отчество и логин изменены", "utf8"))
                    elif z == "4":  # курс
                        new_course = client.recv(1024).decode("utf8")
                        stud.set_course(int(new_course))
                        client.send(bytes("Курс изменен", "utf8"))
                    elif z == "5":
                        new_group = client.recv(1024).decode("utf8")
                        stud.set_group(new_group)
                        client.send(bytes("Группа изменена", "utf8"))
                    else:
                        new_subgroup = client.recv(1024).decode("utf8")
                        stud.set_subgroup(int(new_subgroup))
                        client.send(bytes("Подгруппа изменена", "utf8"))
                    # перезапись файла list.txt
                    update_file(students, admins)
                else:
                    client.send(bytes("Данного студента нет в системе", "utf8"))

            elif msg1 == "6":
                stud = Student()
                surname = client.recv(1024).decode("utf8")
                stud.set_surname(surname)
                name = client.recv(1024).decode("utf8")
                stud.set_name(name)
                patronym = client.recv(1024).decode("utf8")
                stud.set_patronym(patronym)

                # генерация логина
                login = translit(name[0] + patronym[0] + surname)
                stud.set_login(login)

                # генерация пароля
                password = generate_password()
                stud.set_password(password)

                course = client.recv(1024).decode("utf8")
                stud.set_course(int(course))
                group = client.recv(1024).decode("utf8")
                stud.set_group(group)
                subgroup = client.recv(1024).decode("utf8")
                stud.set_subgroup(int(subgroup))
                students.append(stud)
                f = open("server/data/list.txt", "a", encoding="utf8")  # открытие файла на дозапись
                f.write(
                    surname + "*" + name + "*" + patronym + "*" + login + "*" + password + "*" + course + "*" + group + "*" + subgroup + "\n")
                f.close()
                client.send(bytes("Регистрация прошла успешно", "utf8"))

            elif msg1 == "7":  # удаление
                flag = 0
                surname = client.recv(1024).decode("utf8")
                for stud in students:
                    if stud.get_surname() == surname:
                        flag = 1
                        students.remove(stud)
                        update_file(students, admins)
                        client.send(bytes("Студент отчислен!", "utf8"))
                        break
                if flag == 0:
                    client.send(bytes("Данного студента не было в системе", "utf8"))

            elif msg1 == "1":  # зачетка
                flag = 0
                surname = client.recv(1024).decode("utf8")
                for stud in students:
                    if stud.get_surname() == surname:
                        flag = 1
                        msg = str(stud.get_surname()) + " " + str(stud.get_name()) + " " + str(stud.get_patronym()) + \
                              "\n" + "Студент бакалавриата " + str(
                            stud.get_course()) + " курс" + "\n" + "-------------------------------------------------"
                        for obj in disciplines:
                            if int(obj.get_course()) <= int(stud.get_course()):
                                msg = msg + "\n" + str(obj.get_name()) + " " + str(obj.find_mark(str(stud.get_surname())))
                        client.send(bytes(msg, "utf8"))
                        break
                if flag == 0:
                    client.send(bytes("Данного студента нет в системе", "utf8"))

            elif msg1 == "2":  # рейтинг
                msg = show_rating(students, disciplines)
                client.send(bytes(msg, "utf8"))

            elif msg1 == "3":  # смена пароля
                password = client.recv(1024).decode("utf8")
                for adm in admins:
                    if adm.get_surname() == user:
                        adm.set_password(password)
                update_file(students, admins)
                client.send(bytes("Пароль изменен", "utf8"))

            else:  # закрываем соединение
                client.send(bytes("До свидания!", "utf8"))
                client.close()
                break

    else:
        while True:
            msg = client.recv(1024).decode("utf8")  # меню
            if msg == "1":  # зачетка
                msg = str(stud.get_surname()) + " " + str(stud.get_name()) + " " + str(stud.get_patronym()) + \
                      "\n" + "Студент бакалавриата " + str(
                    stud.get_course()) + " курс" + "\n" + "-------------------------------------------------"
                for obj in disciplines:
                    msg = msg + "\n" + str(obj.get_name()) + " " + str(obj.find_mark(str(stud.get_surname())))
                client.send(bytes(msg, "utf8"))
            elif msg == "2":  # рейтинг
                msg = show_rating(students, disciplines)
                client.send(bytes(msg, "utf8"))
            elif msg == "3":
                password = client.recv(1024).decode("utf8")
                for stud in students:
                    if stud.get_surname() == user:
                        stud.set_password(password)
                update_file(students, admins)
                client.send(bytes("Пароль изменен", "utf8"))
            else:
                client.send(bytes("До свидания!", "utf8"))
                client.close()
                break
Example #5
0
    def mainMenu(self):
        keepAlive = True

        while keepAlive:
            try:
                UI.printMenu()
                command = input("Enter command: ").strip()
                if command == '0':
                    print("exit...")
                    keepAlive = False
                elif command == '1':
                    z = self.readStudent()
                    self._controller.addStudent(z)
                    self._controllerU.addCommand(
                        ["AddStudent",
                         Student(z.getId(), z.getName())],
                        ["AddStudent",
                         Student(z.getId(), z.getName())])
                elif command == '2':
                    z = self.ReadDiscipline()
                    self._controllerD.addDiscipline(z)
                    self._controllerU.addCommand(
                        ["AddDiscipline",
                         Discipline(z.getId(), z.getName())],
                        ["AddDiscipline",
                         Discipline(z.getId(), z.getName())])
                elif command == '3':
                    p = int(input("Please give an id:"))
                    name = self._controller.getNameById(p)
                    try:
                        self._controller.remove(p)
                        self._controllerU.addCommand([
                            "removeStudent", Student(p, name)
                        ], ["removeStudent", Student(p, name)])
                        self._controllerG.remove(p)
                    except Exception as ve:
                        print(ve)
                elif command == '4':
                    p = int(input("Please give an id:"))
                    name = self._controllerD.getNameById(p)
                    try:
                        self._controllerD.remove(p)
                        self._controllerU.addCommand(
                            ["removeDiscipline",
                             Discipline(p, name)],
                            ["removeDiscipline",
                             Discipline(p, name)])
                        self._controllerG.remove(p)
                    except Exception as ve:
                        print(ve)
                elif command == '5':
                    for i in self._controller.getAll():
                        print("%d %s" % (i.getId(), i.getName()))
                elif command == '6':
                    for i in self._controllerD.getAll():
                        print(i.getId(), i.getName())
                elif command == "7":
                    x = self.readStudent()  #new one
                    name = self._controller.getNameById(x.getId())
                    y = Student(x.getId(), name)  #old one
                    self._controller.update(x.getId(), x.getName())
                    self._controllerU.addCommand(
                        ["UpdateStudent",
                         Student(y.getId(), y.getName())],
                        ["UpdateStudent",
                         Student(x.getId(), x.getName())])
                elif command == "8":
                    x = self.readUpdate()
                    name = self._controllerD.getNameById(x.getId())
                    y = Discipline(x.getId(), name)
                    self._controllerD.update(x.getId(), x.getName())
                    self._controllerU.addCommand([
                        "UpdateDiscipline",
                        Discipline(y.getId(), y.getName())
                    ], [
                        "UpdateDiscipline",
                        Discipline(x.getId(), x.getName())
                    ])
                elif command == "9":
                    x = UI.ReadGrade(self)
                    self._controllerG.addGrade(x)
                elif command == "10":
                    x = int(input("Id:"))
                    y = self._controller.searchID(x)
                    for i in y:
                        print(i)
                elif command == "11":
                    x = self.readName()
                    y = self._controller.searchName(x)
                    for i in y:
                        print(i)
                elif command == "12":
                    x = int(input("Id:"))
                    y = self._controllerD.searchID(x)
                    for i in y:
                        print(i)
                elif command == "13":
                    x = self.readName()
                    y = self._controllerD.searchName(x)
                    for i in y:
                        print(i)
                elif command == "14":
                    x = int(input(" Discipline Id:"))
                    y = self._controllerG.sortAlphabetically(x)
                    for i in y:
                        print(i.getSname())
                elif command == "15":
                    x = int(input("Discipline Id:"))
                    y = self._controllerG.sortByMean(x)
                    for i in y:
                        print(i.getSname(), i.getGValue())
                elif command == "16":
                    y = self._controllerG.FailAnExam()
                    for i in y:
                        print(i.getSname(), i.getGValue())
                elif command == "17":
                    self._controllerU.undo()

                elif command == "18":
                    self._controllerU.redo()
            except Exception:
                print("Invalid parameters")
Example #6
0
    def ReadDiscipline(self):
        i = int(input("Discipline id"))
        r = input("Discipline=")

        return Discipline(i, r)
Example #7
0
 def readUpdate(self):
     r = int(input("Id for discipline to be change: "))
     i = input("New discipline: ")
     return Discipline(r, i)
    disciplineRepo = DisciplineRepoBinary(result[2][1].strip())
    gradeRepo = GradeRepoBinary(result[3][1].strip())
else:
    print("Invalid text in settings.properties")

studentCtrl = StudentCtrl(repo)

studentCtrl.addStudent(Student(1, "eminescu"))
studentCtrl.addStudent(Student(2, "enescu"))
studentCtrl.addStudent(Student(3, "badita"))
studentCtrl.addStudent(Student(111, "gangos"))

#
disciplineCtrl = DisciplineCtrl(disciplineRepo)

disciplineCtrl.addDiscipline(Discipline(2, "maths"))
disciplineCtrl.addDiscipline(Discipline(1, "english"))
disciplineCtrl.addDiscipline(Discipline(3, "physics education"))
disciplineCtrl.addDiscipline(Discipline(11, "computer science"))

#

gradeCtrl = GradeCtrl(gradeRepo)

gradeCtrl.addGrade(Grade(1, "Ana", 1, "maths", 3))
gradeCtrl.addGrade(Grade(10, "Tini", 2, "maths", 8))
gradeCtrl.addGrade(Grade(11, "Toni", 2, "maths", 6))
gradeCtrl.addGrade(Grade(3, "Ion", 1, "english", 2))
gradeCtrl.addGrade(Grade(2, "Gigi", 1, "english", 7.5))
gradeCtrl.addGrade(Grade(4, "Mihnea", 1, "english", 8))
gradeCtrl.addGrade(Grade(5, "Gheorghe", 1, "english", 9))