Ejemplo n.º 1
0
def download(course, item):
    """
    Download announcement JSON.
    :param course: A Course object.
    :param item: {
        "close_time": 2147483647,
        "user_id": 1069689,
        "open_time": 1411654451,
        "title": "Coursera",
        "deleted": 0,
        "email_announcements": "email_sent",
        "section_id": "14",
        "order": "6",
        "item_type": "announcement",
        "__type": "announcement",
        "published": 1,
        "item_id": "39",
        "message": "Hello, everyone.",
        "uid": "announcement39",
        "id": 39,
        "icon": ""
    }
    :return: None.
    """
    path = '{}/announcement/{}.json'
    path = path.format(course.get_folder(), item['item_id'])

    util.make_folder(path, True)
    util.write_json(path, item)

    content = util.read_file(path)
    content = util.remove_coursera_bad_formats(content)

    util.write_file(path, content)
Ejemplo n.º 2
0
Archivo: wiki.py Proyecto: kq2/Ricin
def download(course, item):
    """
    Download a wiki page.
    :param course: A Course object.
    :param item: {
        "uid": "coursepageEYJIs_YAEeKNdCIACugoiw",
        "section_id": "27",
        "order": "1",
        "item_type": "coursepage",
        "__type": "coursepage",
        "item_id": "EYJIs_YAEeKNdCIACugoiw",
        "id": "EYJIs_YAEeKNdCIACugoiw",
        "metadata": {
            "openTime": 1373785724930,
            "locked": true,
            "creator": 726142,
            "title": "Home",
            "modified": 1405321775510,
            "canonicalName": "home",
            "created": 1374849092873,
            "visible": true,
            "version": 11
        }
    }
    :return: None.
    """
    # path = '{}/wiki/info/{}.json'
    # path = path.format(course.get_folder(), item['metadata']['canonicalName'])
    #
    # util.make_folder(path, True)
    # util.write_json(path, item)
    #
    url = '{}/admin/api/pages/{}?fields=content'
    url = url.format(course.get_url(), item['item_id'])

    path = '{}/wiki/{}.html'
    path = path.format(course.get_folder(), item['metadata']['canonicalName'])

    util.download(url, path, course.get_cookie_file())

    wiki = util.read_json(path)
    content = wiki['content']
    if content:
        content = util.remove_coursera_bad_formats(content)
    else:
        content = ''

    util.write_file(path, content)
Ejemplo n.º 3
0
Archivo: quiz.py Proyecto: kq2/Ricin
def download(course, item):
    """
    Download quiz XML.
    :param course: A Course object.
    :param item: {
        "last_updated": 1409275771,
        "authentication_required": 1,
        "proctoring_requirement": "none",
        "open_time": 1409263200,
        "parent_id": 87,
        "soft_close_time": 1409752800,
        "duration": 0,
        "maximum_submissions": 1,
        "deleted": 0,
        "section_id": "6",
        "__type": "quiz",
        "order": "8",
        "item_type": "quiz",
        "quiz_type": "survey",
        "hard_close_time": 1409925600,
        "item_id": "87",
        "title": "Welcome Survey",
        "__published": 1,
        "id": 88,
        "uid": "quiz88"
    }
    :return: None.
    """
    # path = '{}/quiz/info/{}.json'
    # path = path.format(course.get_folder(), item['item_id'])
    #
    # util.make_folder(path, True)
    # util.write_json(path, item)
    #
    url = '{}/admin/quiz/raw_edit?quiz_id={}'
    url = url.format(course.get_url(), item['item_id'])

    path = '{}/quiz/{}.xml'
    path = path.format(course.get_folder(), item['item_id'])

    util.download(url, path, course.get_cookie_file())

    pattern = r'<textarea.*?>(.*)</textarea>'
    xml = re.search(pattern, util.read_file(path), re.DOTALL).group(1)
    xml = util.remove_coursera_bad_formats(xml)
    xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + xml

    util.write_file(path, xml)
Ejemplo n.º 4
0
Archivo: video.py Proyecto: kq2/Ricin
def _download_in_video_quizzes(course, item):
    """
    Download in-video quizzes.
    """
    path = '{}/video/quizzes/{}.json'
    path = path.format(course.get_folder(), item['item_id'])

    if item['__in_video_quiz_v2']:
        _download_new_quizzes(course, item, path)
    else:
        _download_old_quizzes(course, item, path)

    if util.exists(path):
        content = util.read_file(path)
        content = util.remove_coursera_bad_formats(content)
        util.write_file(path, content)
Ejemplo n.º 5
0
Archivo: peer.py Proyecto: kq2/Ricin
def download(course, item):
    """
    Download peer-grading JSON.
    :param course: A Course object.
    :param item: This JSON item is directly written into saved file.
    :return: None.
    """
    path = "{}/peer_assessment/{}.json"
    path = path.format(course.get_folder(), item["item_id"])

    util.make_folder(path, True)
    util.write_json(path, item)

    content = util.read_file(path)
    content = util.remove_coursera_bad_formats(content)

    util.write_file(path, content)
Ejemplo n.º 6
0
def download(course, item):
    """
    Download assignment HTML.
    :param course: A Course object.
    :param item: {
        "maximum_submissions": 0,
        "open_time": 1409234400,
        "parent_id": 5,
        "soft_close_time": 1409965200,
        "title": "Module 1: Circles",
        "deleted": 0,
        "section_id": "6",
        "order": "9",
        "item_type": "assignment",
        "__type": "assignment",
        "hard_close_time": 1410138000,
        "item_id": "5",
        "last_updated": 1409236863,
        "__published": 1,
        "id": 6,
        "uid": "assignment6"
    }
    :return: None.
    """
    # path = '{}/assignment/info/{}.json'
    # path = path.format(course.get_folder(), item['item_id'])
    #
    # util.make_folder(path, True)
    # util.write_json(path, item)
    #
    url = '{}/admin/assignment?assignment_id={}'
    url = url.format(course.get_url(), item['item_id'])

    path = '{}/assignment/{}.html'
    path = path.format(course.get_folder(), item['item_id'])

    util.download(url, path, course.get_cookie_file())

    pattern = r'<textarea.*?>(.*)</textarea>'
    content = re.search(pattern, util.read_file(path), re.DOTALL).group(1)
    content = util.remove_coursera_bad_formats(content)

    util.write_file(path, content)