1
0

feat: create first prototype of script

This commit is contained in:
Rokas Puzonas 2021-12-17 20:15:14 +02:00
parent 3313fbddae
commit 4451519229
3 changed files with 72 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
venv
.env
*.log
__pycache__

52
main.py
View File

@ -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()

View File

@ -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