示例#1
0
def download_file(brightspace_api, item, path, course, output_dir):
    filepath = create_filepath(course, path)
    description = item["Description"]["Html"]
    topic_type = item["TopicType"]
    title = item["Title"]
    url = item["Url"]
    if topic_type == 1:
        filename = create_filename(item)
        filename_without_extension = ".".join(filename.split(".")[:-1])
        full_path = f"{output_dir}/{filepath}/{filename}"
        # These documents are regular files that we want to download
        download_from_url(brightspace_api, f"""{ufora}{url}""", full_path)
        if url.endswith(".html"):
            # HTML files on Ufora need a little special treatment
            # We'll prepend a title, <base> tag and convert them to pdf
            with open(full_path, "r") as f:
                content = f.read()
            filename_without_extension = ".".join(filename.split(".")[:-1])
            description_path = f"{output_dir}/{filepath}/{filename_without_extension}.pdf"
            create_metadata(description_path, content,
                            filename_without_extension)
            new_content = f"<base href={ufora}><h1>{title}</h1>{content}"
            with open(full_path, "w") as f:
                f.write(new_content)
        elif description:
            description_path = f"{output_dir}/{filepath}/{filename_without_extension}_metadata.pdf"
            create_metadata(description_path, description,
                            filename_without_extension)
        if url.endswith(".pptx") or url.endswith(".ppt"):
            # ppt and pptx files can be converted to PDF if unoconv is present
            new_pdf_path = f"{output_dir}/{filepath}/{filename_without_extension}_converted.pdf"
            if not os.path.isfile(new_pdf_path):
                convert_to_pdf(full_path, new_pdf_path)

    elif topic_type == 3:
        # These documents are just clickable links, we'll render them in a pdf
        filename = create_filename_without_extension(item)
        full_path = f"{output_dir}/{filepath}/{filename}"
        create_metadata(f"{full_path}.pdf",
                        f"<a href={url}>{url}</a>{description}", item["Title"])
    else:
        print(f"Don't know this topic type: {topic_type}")
        exit()
示例#2
0
def download_file(brightspace_api, item, path, course, output_dir):
    filepath = create_filepath(course, path)
    description = item["Description"]["Html"]
    topic_type = item["TopicType"]
    title = item["Title"]
    if topic_type == 1:
        filename = create_filename(item)
        full_path = f"{output_dir}/{filepath}/{filename}"
        # These documents are real files that we want to download
        download_from_url(brightspace_api, f"""{ufora}{item["Url"]}""",
                          full_path)
        if item["Url"].endswith(".html"):
            # HTML files on Ufora need a little special treatment
            # We'll prepend a title, <base> tag and convert them to pdf
            with open(full_path, "r") as f:
                content = f.read()
            filename_without_extension = ".".join(filename.split(".")[:-1])
            description_path = f"{output_dir}/{filepath}/{filename_without_extension}.pdf"
            create_metadata(description_path, content,
                            filename_without_extension)
            new_content = f"<base href={ufora}><h1>{title}</h1>{content}"
            with open(full_path, "w") as f:
                f.write(new_content)
        elif description:
            # Choosing this filename might cause an overlap...
            filename_without_extension = ".".join(filename.split(".")[:-1])
            description_path = f"{output_dir}/{filepath}/{filename_without_extension}.pdf"
            create_metadata(description_path, description,
                            filename_without_extension)
    elif topic_type == 3:
        # These documents are just clickable links, we'll render them in a pdf
        url = item["Url"]
        filename = create_filename_without_extension(item)
        full_path = f"{output_dir}/{filepath}/{filename}"
        create_metadata(f"{full_path}.pdf",
                        f"<a href={url}>{url}</a>{description}", item["Title"])
    else:
        print(f"Don't know this topic type: {topic_type}")
        exit()
示例#3
0
def download_module(item, path, course, output_dir):
    description = item["Description"]["Html"]
    if description:
        filepath = create_filepath(course, path)
        description_path = f"{output_dir}/{filepath}/metadata.pdf"
        create_metadata(description_path, description, filepath.split("/")[-1])