~tieong/download-course

b75cc3a9765be8ecd7dc3e780c7d697177cfa0c0 — Thomas Ieong 2 years ago ef6fdf7
The user and the password now needs to be set in the env variables
M README.md => README.md +10 -2
@@ 1,9 1,17 @@
# Download REPLACE_ME courses

Short script to download courses from the REPLACE_ME platform
Short script to download courses from the REPLACE_ME platform.
Need to set the username and the password as environment variables.

```
download_course -u <user> -p <password> --city REPLACE_ME --promotion REPLACE_MEREPLACE_ME -o ~/Téléchargements
export REPLACE_ME_USERNAME=<username>
export REPLACE_ME_PASSWORD=<password>

download_course --city REPLACE_ME --promotion REPLACE_MEREPLACE_ME -o ~/Téléchargements

or

REPLACE_ME_USERNAME=<user> REPLACE_ME_PASSWORD=<password> download_course --city REPLACE_ME --promotion REPLACE_MEREPLACE_ME -o ~/Téléchargements
```

## Bug

M download_course/download_course.py => download_course/download_course.py +7 -2
@@ 6,6 6,7 @@ import logging
import argparse
import pathlib
import re
import os
from typing import List

from bs4 import BeautifulSoup


@@ 375,12 376,16 @@ def download_courses(
) -> None:
    """Download courses files on the moodle platform."""
    REPLACE_ME_page = REPLACE_MEPage(REPLACE_ME_session)
    REPLACE_ME_page.connect_to_REPLACE_ME(args.username, args.password)
    username = os.getenv("REPLACE_ME_USERNAME")
    password = os.getenv("REPLACE_ME_PASSWORD")
    if not username or not password:
        raise ValueError("The username or the password is not set!")
    REPLACE_ME_page.connect_to_REPLACE_ME(username, password)
    REPLACE_ME_page.click_on_formation_button()
    REPLACE_ME_page.click_on_REPLACE_ME_platform(args.city)

    REPLACE_ME_page = REPLACE_MEPage(REPLACE_ME_session, REPLACE_ME_page.soup)
    REPLACE_ME_page.connect_to_moodle(args.username, args.password)
    REPLACE_ME_page.connect_to_moodle(username, password)
    REPLACE_ME_page.click_courses_button()
    REPLACE_ME_page.click_course_section()
    REPLACE_ME_page.select_course_category(args.promotion)

M download_course/utils/config_json.py => download_course/utils/config_json.py +0 -1
@@ 32,7 32,6 @@ elif sys.platform == "darwin":
    )



def init_config() -> None:
    """Init the json if it doesn't exists"""
    logging.info("The config file is located at %s", STORAGE_FILE)

M download_course/utils/prompt.py => download_course/utils/prompt.py +0 -18
@@ 9,24 9,6 @@ import pathlib
def get_args() -> argparse.Namespace:
    """Parse arguments given on the command line"""
    parser = argparse.ArgumentParser()
    # Username
    parser.add_argument(
        '-u',
        '--username',
        action="store",
        help="Username to log into REPLACE_ME services.",
        type=str,
        required=True
    )
    # Password
    parser.add_argument(
        '-p',
        '--password',
        action="store",
        help="Password to log into REPLACE_ME services.",
        type=str,
        required=True
    )
    # City
    parser.add_argument(
        '--city',