예제 #1
0
def test_quiz_converter_all():
    pytest.skip()
    import os

    from coursera.coursera_dl import get_session
    from coursera.cookies import login
    session = None
    session = get_session()

    quiz_to_markup = api.QuizExamToMarkupConverter(session=session)
    markup_to_html = api.MarkupToHTMLConverter(session=session)

    path = 'quiz_json'
    for filename in ['quiz-audio.json']:  # os.listdir(path):
        # for filename in ['all_question_types.json']:
        # if 'YV0W4' not in filename:
        #     continue
        # if 'QVHj1' not in filename:
        #     continue

        #quiz_data = json.load(open('quiz.json'))['contentResponseBody']['return']
        current = os.path.join(path, filename)
        print(current)
        quiz_data = json.load(open(current))
        result = markup_to_html(quiz_to_markup(quiz_data))
        # from ipdb import set_trace; set_trace(context=20)
        # print('RESULT', result)
        with open('quiz_html/' + filename + '.html', 'w') as f:
            f.write(result)
예제 #2
0
def test_quiz_converter_all():
    pytest.skip()
    import os

    from coursera.coursera_dl import get_session
    from coursera.cookies import login
    session = None
    session = get_session()

    quiz_to_markup = api.QuizExamToMarkupConverter(session=session)
    markup_to_html = api.MarkupToHTMLConverter(session=session)

    path = 'quiz_json'
    for filename in ['quiz-audio.json']: #os.listdir(path):
    # for filename in ['all_question_types.json']:
        # if 'YV0W4' not in filename:
        #     continue
        # if 'QVHj1' not in filename:
        #     continue

        #quiz_data = json.load(open('quiz.json'))['contentResponseBody']['return']
        current = os.path.join(path, filename)
        print(current)
        quiz_data = json.load(open(current))
        result = markup_to_html(quiz_to_markup(quiz_data))
        # from ipdb import set_trace; set_trace(context=20)
        # print('RESULT', result)
        with open('quiz_html/' + filename + '.html', 'w') as f:
            f.write(result)
예제 #3
0
    def login(self, cauth):
        """
        Login function creates an authorized TLS session.

        @param  : args: It takes CAUTH <class 'str'> Token to make user authorized.
        @return : <class 'bool'> which indicates to success of the process.
        """
        if (not self._inColab) and (not self._debug):
            return False

        self.cauth = cauth
        self.session = get_session()
        self.session.cookies.set('CAUTH', self.cauth)

        if (self._enrolledCourses()):
            print("=" * 100)
            print("You have enrolled {} course.".format(self._totalEnrolled))
            print(
                "If you want to see enrolled courses call printEnrolledCourses() method!\n"
            )
            self._loginFlag = True
            self._allCourses()
            print("Coursera has {} courses now.".format(self._totalCourses))
            print(
                "If you want to see all courses call printAllCourses() method!"
            )
            print("=" * 100, end="\n\n")

        else:
            print("Login Error!")
            self._loginFlag = False
예제 #4
0
def create_session():
    from coursera.coursera_dl import get_session
    from coursera.credentials import get_credentials
    from coursera.cookies import login

    session = get_session()
    username, password = get_credentials(netrc=expanduser('~/.netrc'))
    login(session, username, password)
    return session
예제 #5
0
def create_session():
    from coursera.coursera_dl import get_session
    from coursera.credentials import get_credentials
    from coursera.cookies import login

    session = get_session()
    username, password = get_credentials(netrc=expanduser('~/.netrc'))
    login(session, username, password)
    return session