From 4451519229a828381c05d24a0ebd16a6125dbd0c Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Fri, 17 Dec 2021 20:15:14 +0200 Subject: [PATCH] feat: create first prototype of script --- .gitignore | 2 ++ main.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++- requirements.txt | 19 ++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4ee96a0..4461696 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ venv +.env +*.log __pycache__ diff --git a/main.py b/main.py index aced72c..3cb079f 100755 --- a/main.py +++ b/main.py @@ -1,7 +1,57 @@ #!/usr/bin/env python +from selenium import webdriver +from selenium.webdriver.firefox.options import Options +from selenium.webdriver.common.by import By +from dotenv import load_dotenv +import time +import os +from os import path + +LOGIN_URL = "https://moodle.ktu.edu/login/index.php" +EDIT_ASSIGNMENT_URL = "https://moodle.ktu.edu/mod/assign/view.php?id=1499&action=editsubmission" + +moodle_filename = "IF-1-1_Rokas_Puzonas.pdf" +filename = "report.pdf" def main(): - pass + load_dotenv() + + options = Options() + # options.headless = True + driver = webdriver.Firefox(options=options) + + driver.get(LOGIN_URL) + driver.find_element(By.ID, "username").send_keys(os.environ["KTU_USERNAME"]) + driver.find_element(By.ID, "password").send_keys(os.environ["KTU_PASSWORD"]) + driver.find_element(By.XPATH, "//input[@type='submit']").click() + time.sleep(1) + + driver.find_element(By.ID, "yesbutton").click() + time.sleep(1) + + driver.get(EDIT_ASSIGNMENT_URL) + time.sleep(1) + + file = driver.find_element(By.XPATH, f"//*[text()='{moodle_filename}']") + if file: + file.click() + time.sleep(1) + driver.find_element(By.XPATH, "//button[text()='Naikinti']").click() + time.sleep(1) + driver.find_element(By.XPATH, "//button[contains(@class, 'fp-dlg-butconfirm')]").click() + time.sleep(1) + + driver.find_element(By.CLASS_NAME, "filemanager-container").click() + time.sleep(1) + + driver.find_element(By.XPATH, "//input[@type='file']").send_keys(path.abspath(filename)) + driver.find_element(By.XPATH, "//input[@name='title']").send_keys(moodle_filename) + driver.find_element(By.CLASS_NAME, "fp-upload-btn").click() + time.sleep(1) + + driver.find_element(By.ID, "id_submitbutton").click() + + driver.close() if __name__ == "__main__": main() diff --git a/requirements.txt b/requirements.txt index 6180328..a596767 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,20 @@ +async-generator==1.10 +attrs==21.2.0 +certifi==2021.10.8 +cffi==1.15.0 click==8.0.3 +cryptography==36.0.1 +h11==0.12.0 +idna==3.3 +outcome==1.1.0 +pycparser==2.21 +pyOpenSSL==21.0.0 +python-dotenv==0.19.2 +selenium==4.1.0 +six==1.16.0 +sniffio==1.2.0 +sortedcontainers==2.4.0 +trio==0.19.0 +trio-websocket==0.9.2 +urllib3==1.26.7 +wsproto==1.0.0