Beispiel #1
0
def create_CSVs_from_channeldir(channeldir):

    # Open a writer to generate files
    with data_writer.DataWriter(write_to_path=WRITE_TO_PATH) as writer:

        # Write channel details to spreadsheet
        thumbnail = writer.add_file('.',
                                    "channel_thumbnail",
                                    'content/channel_thumbnail.jpg',
                                    write_data=False)
        writer.add_channel(CHANNEL_NAME,
                           CHANNEL_SOURCE_ID,
                           CHANNEL_DOMAIN,
                           CHANNEL_LANGUAGE,
                           description=CHANNEL_DESCRIPTION,
                           thumbnail=thumbnail)

        content_folders = list(os.walk(channeldir))

        # MAIN PROCESSING OF os.walk OUTPUT
        ############################################################################
        _ = content_folders.pop(
            0)  # Skip over channel folder because handled above
        for rel_path, _subfolders, filenames in content_folders:
            process_folder(writer, channeldir, rel_path, filenames)

        sys.stdout.write("\n\nDONE: Zip created at {}\n".format(
            writer.write_to_path))
    """ Creates folders and files from resources """
    resource_data = resource_data or []
    PATH.open_folder(resource_name)       # Add resource to path (Topic hierarchy: Subject -> Book -> Resource)
    writer.add_folder(str(PATH), resource_name)
    for resource in resource_data:
        if resource.get('link_document_url'):
            _name, ext = os.path.splitext(resource['link_document_url'])
            if ext.lower() == ".pdf":
                title = resource.get('resource_heading')
                description = parse_description(resource.get('resource_description'))
                LOGGER.info("      Writing resource {}...".format(title))
                writer.add_file(str(PATH), title, resource.get("link_document_url"), description=description, **auth_info)

    PATH.go_to_parent_folder() # Go back one step in path (Topic hierarchy: Subject -> Book)


""" This code will run when the sushi chef is called from the command line. """
if __name__ == '__main__':

    # Open a writer to generate files
    with data_writer.DataWriter(write_to_path=WRITE_TO_PATH) as writer:

        # Write channel details to spreadsheet
        thumbnail = writer.add_file(str(PATH), "Channel Thumbnail", CHANNEL_THUMBNAIL, write_data=False)
        writer.add_channel(CHANNEL_NAME, CHANNEL_SOURCE_ID, CHANNEL_DOMAIN, CHANNEL_LANGUAGE, description=CHANNEL_DESCRIPTION, thumbnail=thumbnail)

        # Scrape source content
        scrape_source(writer)

        sys.stdout.write("\n\nDONE: Zip created at {}\n".format(writer.write_to_path))