示例#1
0
def main(args) -> None:
    client = BlackBoardClient(username=args.username,
                              password=args.password,
                              site=args.site,
                              thread_count=int(args.num_threads),
                              institute=args.institute,
                              save_location=args.location,
                              use_manifest=args.record,
                              backup_files=args.backup)
    if client.login():
        if not client.use_rest_api:
            input(
                "Your Blackboard Learn Service Doesn't Support the use of the rest API.\nXML request development is "
                "currently being worked on and should be available soon...\n\nPress Any Key to Exit"
            )
            sys.exit(0)
        if not client.public_endpoint_avaliable():
            input(
                "The /public/ endpoint of of API is not accessible.\nUnfornatley this is required for this application to function...\n\nPress Any Key to Exit"
            )
            sys.exit(0)
        save_config(args)
        for course in args.additional_courses:  # Append Additional Courses
            client.add_course(course)
        if args.mass_download:
            for course in client.courses():
                if args.course is None or course.id == args.course:  # Download only Specified Course
                    course.download_all_attachments(args.location,
                                                    args.threaded)
        else:
            navigate(client)
    else:
        if input("Failed to Login [Enter 'r' to Retry]") == 'r':
            handle_arguments()
    return
def main(args):
    global ARGS
    ARGS = args
    bbc = BlackBoardClient(username=args.username,
                           password=args.password, site=args.site)
    if bbc.login():
        if not bbc.use_rest_api:
            input("Your Blackboard Learn Service Doesnt Support the use of the rest API.\nXML request development is "
                  "currently being worked on and should be available soon")
            sys.exit(0)
        save_config(args)
        if args.mass_download:
            courses = bbc.courses()  # get all Courses
            for course in ARGS.additional_courses:
                courses.appened(BlackBoardCourse(bbc, course))
            for course in courses:
                if args.course is None or course.id == args.course:  # Download only Specified Course
                    course.download_all_attachments(ARGS.location)
        else:
            navigate(bbc)
    else:
        if input("Failed to Login [Enter 'r' to Retry]") == 'r':
            main(args)
    return
def main(args) -> None:
    """
    The Main Function That is Used to Traverse the Blackboard Content
    :param args: The Parsed Arguments from the CLI, Configuration File and Inputs
    """

    client = BlackBoardClient(username=args.username,
                              password=args.password,
                              site=args.site,
                              thread_count=int(args.num_threads),
                              institute=args.institute,
                              save_location=args.location,
                              use_manifest=args.record,
                              backup_files=args.backup)
    login_resp = client.login()
    if login_resp[0]:
        signal.signal(signal.SIGINT, client.stop_threaded_downloads
                      )  # Hook SIGINT (ctrl + c) so we can kill threads
        if not client.use_rest_api:
            input(
                "Your Blackboard Learn Service Doesn't Support the use of the rest API.\nXML request development is "
                "currently being worked on and should be available soon...\n\nPress Any Key to Exit"
            )
            sys.exit(0)
        if not client.public_endpoint_available():
            input(
                "The /public/ endpoint of of API is not accessible.\nUnfortunately this is required for this "
                "application to function...\n\nPress Any Key to Exit")
            sys.exit(0)
        save_config(args)
        for course in args.additional_courses:  # Append Additional Courses
            client.add_course(course)
        if args.mass_download:
            try:
                for course in client.courses():
                    if args.course is None or course.id == args.course:  # Download only Specified Course
                        course.download_all_attachments(
                            args.location, args.threaded)
            except DownloadQueue.DownloadQueueCancelled:  # We Have Shutdown The Downloads
                print(f"Cancelling All Remaining Downloads...")
        else:
            navigate(client)
    else:
        if input("FAILED TO LOGIN\n" + f"Username: {args.username}\n" +
                 f"Learn Site: {args.site}\n" +
                 f"Response Status Code: {login_resp[1].status_code}\n" +
                 f"Response Body: {login_resp[1].text}\n\n\n" +
                 "[Enter 'r' to Retry]") == 'r':
            clear_console()
            handle_arguments()
    return
def test():
    args = main.handle_arguments(True)
    session = requests.Session()
    # Institute Data
    institute_data = dict()
    institute_vars = vars(args.institute)
    for item in institute_vars:
        institute_data[item] = institute_vars[item]
    # Client Data
    client_data = dict()
    client = BlackBoardClient(username=args.username,
                              password=args.password,
                              site=args.site)

    def login():
        client_data["login_endpoint"] = args.institute.b2_url + "sslUserLogin"
        login_attempt = session.post(args.institute.b2_url + "sslUserLogin",
                                     data={
                                         'username': args.username,
                                         'password': args.password
                                     })
        client_data["login_status_code"] = login_attempt.status_code
        if login_attempt.status_code == 200:
            client_data["response"] = xmltodict.parse(login_attempt.text)
            xml = xmltodict.parse(login_attempt.text)['mobileresponse']
            if xml['@status'] == 'OK':
                return True
        return False

    attempt = login()
    client_data["successful_login"] = attempt
    client.login()
    client_vars = vars(client)
    for item in client_vars:
        if item not in ('_BlackBoardClient__password', 'session', 'institute',
                        'api_version'):
            client_data[item] = client_vars[item]
    # Get Parent Course Data
    course_data = {
        'endpoint': '',
        'status_code': '',
        'response': '',
        'courses': []
    }

    def get_courses():
        request = session.get(
            args.institute.display_lms_host +
            BlackBoardEndPoints.get_user_courses(client.user_id))
        courses = request.json()
        course_data[
            'endpoint'] = args.institute.display_lms_host + BlackBoardEndPoints.get_user_courses(
                client.user_id)
        course_data['status_code'] = request.status_code
        course_data['response'] = courses
        if "results" in courses:
            for course in courses["results"]:
                try:
                    bbcourse = BlackBoardCourse(client, course["courseId"])
                    course_vars = vars(bbcourse)
                    course_sub_data = dict()
                    course_sub_data[
                        "course_endpoint"] = client.site + BlackBoardEndPoints.get_course(
                            course["courseId"])
                    for item in course_vars:
                        course_sub_data[item] = str(course_vars[item])
                    course_data['courses'].append(course_sub_data)
                except Exception as e:
                    course_data['courses'].append({'error': str(e)})

    get_courses()

    dumps = {
        'institute': institute_data,
        'client': client_data,
        'courses': course_data,
    }
    with open("dump.json", 'w') as file:
        json.dump(dumps, file)
示例#5
0
def test():
    args = main.handle_arguments(True)
    # Institute Data
    print("Dumping Institute Properties...")
    institute_data = dict()
    institute_vars = vars(args.institute)
    for item in institute_vars:
        institute_data[item] = institute_vars[item]
    print("Dumped Institute Properties...")
    # Client Data
    client_data = dict()
    client = BlackBoardClient(username=args.username, password=args.password, site=args.site, save_location=args.location, institute=args.institute)
    attempt = client.login()
    print(f"Client Login {'Successful' if attempt[0] else 'Failure'}...\nDumping Client Properties...")
    client_data["public_api_available"] = client.public_endpoint_available()
    client_data["login_endpoint"] = attempt[1].url
    client_data["login_status_code"] = attempt[1].status_code
    client_data["login_response"] =  attempt[1].text
    client_data["successful_login"] = attempt[0]
    client_vars = vars(client)
    for item in client_vars:
        if item not in ('_BlackBoardClient__password', 'session', 'institute', 'api_version', 'thread_pool'):
            client_data[item] = client_vars[item]
    print("Dumped Client Properties...")
    # Get Parent Course Data
    course_data = {
        'endpoint': '',
        'status_code': '',
        'response': '',
        'courses': []
    }

    def get_courses():
        """
        Get all Available Course Information for the Client and Record Details
        """
        courses_request = client.send_get_request(BlackBoardEndPoints.get_user_courses(client.user_id))
        courses = courses_request.json()
        course_data['endpoint'] = courses_request.url
        course_data['status_code'] = courses_request.status_code
        course_data['response'] = courses
        if "results" in courses:
            for course in courses["results"]:
                try:
                    course_request = client.send_get_request(BlackBoardEndPoints.get_course(course["courseId"]))
                    course = course_request.json()
                    bbcourse = BlackBoardCourse(client, course)
                    course_vars = vars(bbcourse)
                    course_sub_data = dict()
                    course_sub_data["course_endpoint"] = course_request.url
                    course_sub_data['status_code'] = course_request.status_code
                    for item in course_vars:
                        course_sub_data[item] = str(course_vars[item])
                    course_data['courses'].append(course_sub_data)
                except Exception as e:
                    course_data['courses'].append({'error': str(e)})

    print("Getting Course Data...")
    get_courses()
    print("Completed Course Data...")
    dumps = {
        'institute': institute_data,
        'client': client_data,
        'courses': course_data,
    }
    print("Preparing to Dump Debug...")
    with open(os.path.abspath(os.path.join(client.base_path, "dump.json")), 'w+') as file:
        print(f"Writing File: \"{file.name}\"...")
        json.dump(dumps, file)
    print("Done...")