Beispiel #1
0
    def import_csv(self):
        msg = QMessageBox()
        msg.setIcon(QMessageBox.Critical)
        try:
            path, _ = QtWidgets.QFileDialog.getOpenFileName(
                self.student_list_window, "Open Image", ".",
                "Image Files (*.csv)")

            with open(path, "r") as f_obj:
                reader = csv.reader(f_obj)
                student = Student()
                students = student.show_name(self.session, self.group_number)

                for row in reader:
                    fio = row[0]
                    number = row[1]
                    note = row[2]
                    flag_s = 0
                    for s in students:
                        if fio == s:
                            flag_s = 1
                            break

                    if flag_s == 0:
                        student.add(self.session, fio, number, note,
                                    self.group_number)
                        number_row = self.tableWidget.rowCount()
                        self.tableWidget.setRowCount(number_row + 1)
                        self.tableWidget.setItem(
                            number_row, 0, QtWidgets.QTableWidgetItem(fio))
                        self.tableWidget.setItem(
                            number_row, 1,
                            QtWidgets.QTableWidgetItem(str(number)))
                        self.tableWidget.setItem(
                            number_row, 2,
                            QtWidgets.QTableWidgetItem(str(note)))
                        self.tableWidget.resizeColumnsToContents()

            msg.setText("Импорт выполнен")
            msg.setInformativeText('Импорт данных из CSV выполнен.')
            msg.setWindowTitle("Импорт выполнен")

        except:
            msg.setText("Импорт не выполнен")
            msg.setInformativeText('Импорт данных из CSV не выполнен.')
            msg.setWindowTitle("Импорт не выполнен")
        msg.exec_()
Beispiel #2
0
    def add(self):
        fio = self.lineEdit.text()
        number = self.lineEdit_2.text()
        note = self.textEdit.toPlainText()

        student = Student()
        student.add(self.session, fio, number, note, self.group_number)

        row = self.table.rowCount()

        self.table.setRowCount(row + 1)
        self.table.setItem(row, 0, QtWidgets.QTableWidgetItem(fio))
        self.table.setItem(row, 1, QtWidgets.QTableWidgetItem(number))
        self.table.setItem(row, 2, QtWidgets.QTableWidgetItem(note))
        self.table.resizeColumnsToContents()

        self.add_student_window.close()
Beispiel #3
0
def moodle_students(address, login, password, session, group_number) -> int:

    login_address = address + "/login/index.php"

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--ignore-certificate-errors")

    driver = webdriver.Chrome(ChromeDriverManager().install(),
                              chrome_options=chrome_options)

    try:
        driver.get(login_address)
        username = driver.find_element_by_id('username')
        username.click()
        username.send_keys(login)
        password_ = driver.find_element_by_id("password")
        password_.click()
        password_.send_keys(password)
        submit = driver.find_element_by_id("loginbtn")
        submit.click()
        time.sleep(1)

        number_course = 0

        while number_course != -1:
            courses = driver.find_elements_by_class_name(
                'list-group-item-action')
            flag = 0
            this_number_course = 0
            flag_number_course = 0
            for course in courses:
                if flag == 1 and this_number_course == number_course:

                    c = course
                    c.click()
                    driver.find_element_by_partial_link_text(
                        "Участники").click()
                    time.sleep(5)

                    # Синхронизация групп и студентов
                    i = 0
                    flag_e = 0
                    id_template = "user-index-participants-2_r"
                    while flag_e == 0:
                        try:
                            id = id_template + str(i)
                            tr = driver.find_element_by_id(id)
                            i += 1
                            name = tr.find_elements_by_class_name('c1')
                            name = name[0].text
                            role = tr.find_elements_by_class_name('c3')
                            role = role[0].text
                            group = tr.find_elements_by_class_name('c4')
                            group = group[0].text
                            if role == 'Студент':
                                if group == group_number:
                                    s = Student()
                                    record_book = 0
                                    s.add(session, name, record_book, '',
                                          group_number)

                        except:
                            flag_e = 1
                    driver.back()
                    time.sleep(3)
                    driver.back()
                    time.sleep(3)
                    number_course += 1
                    flag_number_course = 1
                    break

                elif flag == 1:
                    this_number_course += 1
                if course.text == "Личные файлы":
                    flag = 1
            if flag_number_course == 0:
                number_course = -1

        driver.close()
        return 0

    except:
        driver.close()
        return 1