~tieong/download-course

685bbab4956151bad7823b1e838bbe194e069b23 — Thomas Ieong 2 years ago b341602
Added more logging
M download_course/download_course.py => download_course/download_course.py +8 -1
@@ 111,6 111,7 @@ class REPLACE_MEPage():
        self.session = REPLACE_ME_session
        self.soup = soup
        self.courses_brick: List[Tag] = []
        self.files_downloaded = 0

    def connect_to_moodle(self, username: str, password: str) -> None:
        """Connect to moodle."""


@@ 316,7 317,7 @@ class REPLACE_MEPage():
            )
            document_dir.write_bytes(document_dl.content)
        else:
            logging.info(
            logging.debug(
                "The file %s has already been downloaded!",
                file_name
            )


@@ 395,12 396,18 @@ def download_courses(
            args.output_dir,
            args.promotion
        )
    logging.info(
        "The number of files downloaded is : %s",
        REPLACE_ME_page.files_downloaded
    )


def main() -> None:
    """Entry point."""
    args = get_args()
    (args.output_dir / args.promotion).mkdir(exist_ok=True)
    if args.debug:
        logging.getLogger().setLevel(logging.DEBUG)

    REPLACE_ME_session = requests.Session()
    with REPLACE_ME_session:

M download_course/utils/config_json.py => download_course/utils/config_json.py +3 -0
@@ 3,6 3,7 @@
"""Regroup all json concernning the download of courses."""

import sys
import logging
import pathlib
import json
from typing import Dict, Any


@@ 30,6 31,8 @@ elif sys.platform == "darwin":
        'REPLACE_ME-courses.json'
    )

logging.info("The config file is located at %s", STORAGE_FILE)


def init_config() -> None:
    """Init the json if it doesn't exists"""

M download_course/utils/prompt.py => download_course/utils/prompt.py +9 -0
@@ 51,5 51,14 @@ def get_args() -> argparse.Namespace:
        default=pathlib.Path.cwd(),
        type=lambda p: pathlib.Path(p).expanduser().resolve()
    )
    # Debug
    parser.add_argument(
        "--debug",
        action="store_true",
        default=False,
        help=(
            "Verbose output."
        )
    )
    args = parser.parse_args()
    return args