-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (46 loc) · 1.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import typer
import time
from artemis.course_page import ArtemisCourse
from artemis import core as Artemis
from utils.browser import WebDriverSingleton
from utils.config import setup
from utils.print import printer
from utils.general_utils import is_tum_ID, is_valid_artemis_course_link, extract_base_url
app = typer.Typer(pretty_exceptions_show_locals=False, pretty_exceptions_enable=False)
@app.command()
def hello(name: str):
print("Hello World!")
@app.command()
def dl_course(
download_path: str = typer.Option('', help="Specify Download Location"),
username: str = typer.Option(..., prompt=True),
password: str = typer.Option(..., prompt=True),
link: str = typer.Option(..., prompt=True, help="Course-Link from Artemis")
):
if is_tum_ID(username) is False:
printer('Username is not valid TUM-ID. Please try again!')
return
if len(password) < 8:
printer('Password is below 8 characters. Please try again!')
return
if is_valid_artemis_course_link(link) is not True:
printer('Link is not a valid Artemis-Course. Please try again!')
return
setup(username=username, password=password, download_dir=download_path)
printer('Opening Browser..')
sdriver = WebDriverSingleton.get_instance()
printer('Browser successfully opened')
printer('Navigating to Artemis Login Screen')
sdriver.get(extract_base_url(link))
Artemis.enable_dark_mode()
printer('Trying to login with credentials')
if Artemis.login() == False:
printer('Login failed. Please check your credentials and try again!')
return
printer('Successfully logged in')
time.sleep(2)
course = ArtemisCourse(course_link=link)
course.open()
course.download_all_exercises()
if __name__ == "__main__":
app()