def p2p_publish(site, s3):
    if not is_production_bucket(s3.bucket, site.project.S3_BUCKETS):
        puts(colored.red(
            "\nNot publishing to production bucket. Skipping P2P publiction."))
        return

    content = _get_published_content(site, s3)
    content = content.encode('utf-8')
    context = site.get_context(publish=True)

    p2p_slug = context['p2p_htmlstory_slug']
    try:
        title = context['headline']
    except KeyError:
        title = context['title']
    p2p_conn = p2p.get_connection()
    content_item = {
        'slug': p2p_slug,
        'content_item_type_code': 'htmlstory',
        'title': title,
        'body': content,
    }
    p2p_conn.create_or_update_content_item(content_item)

    puts("\n" + colored.green("Published to P2P with slug {}".format(p2p_slug)))
Esempio n. 2
0
def check_if_is_okay_to_publish(photo, BUCKET_NAME):
    """
    Takes a p2p data dict and determines if it is okay to publish this content item. It will return true
    in all cases except when the content is not set to Live and the publish url is the production bucket
    """
    # TODO: Make this work!

    if BUCKET_NAME and BUCKET_NAME.upper() == "PRODUCTION":
        #  If we're publishing live
        working_state = photo['content_item_state_code'].upper()
        if (working_state == "LIVE"):
            # Photo must be set to live when publishing to prod
            return True
        # If it is not set to live, do not output
        print(
            puts(
                colored.red("This photo is NOT set live: {}".format(
                    photo['slug']))))
        return False
    # Since we're either publishing local or staging, go ahead and allow it.
    # IMPORTANT NOTE: This just tests the s3 bucket. If a new bucket is identified
    # and it is named something else, such as "project_prod", then our check
    # will not catch it. The assumption here is that the only live-to-the-public
    # bucket is "production"

    return True
def create_p2p_storylink(site, s3):
    """Create or update a P2P storylink content item when publishing this project"""
    puts("\nAttempting to create P2P storylink for this project ...\n")

    try:
        import p2p
    except ImportError:
        puts(colored.red(
            "The p2p-python package is not installed. Storylink not created.\n"))
        return

    if not is_production_bucket(s3.bucket, site.project.S3_BUCKETS):
        puts(colored.red(
            "Not publishing to production bucket. Skipping storylink creation\n."))
        return

    try:
        p2p_slug = site.project.DEFAULT_CONTEXT['P2P_STORYLINK_SLUG']
    except KeyError:    
        puts(colored.red(
            "P2P_STORYLINK_SLUG not defined in DEFAULT_CONTEXT. Storylink "
            "not created.\n"))
        return

    url = "http://" + s3.bucket

    connection = p2p.get_connection()
    content_item = {
        'slug': p2p_slug,
        'content_item_type_code': 'storylink', 
        'url': url,
        'title': site.project.DEFAULT_CONTEXT['title'],
    }
    created, ci = connection.create_or_update_content_item(content_item)
    if created:
        puts(colored.green(
            "P2P storylink with slug '{slug}' created.\n".format(
                slug=p2p_slug)))
        connection.update_content_item({
            'slug': p2p_slug,
            'content_item_state_code': 'working',    
        })    
        ci['content_item_state_code'] = 'working'
    else:
        puts(colored.green("P2P storylink with slug '{slug}' updated.\n".format(
            slug=p2p_slug)))

    if 'thumbnail_url' not in ci:
        puts(colored.cyan(
            "No thumbnail for storylink.  Be sure to add one in P2P."))
Esempio n. 4
0
def p2p_publish_archiemlstory(site, s3):
    if not is_production_bucket(s3.bucket, site.project.S3_BUCKETS):
        puts(colored.red(
            "\nNot publishing to production bucket. Skipping P2P publiction."))
        return

    context = site.get_context(publish=True)

    # Handle old-style configuration for publishing HTML story from values
    # worksheet. This is deprecated, but still support it in case someone
    # accidentally upgrades their blueprint in an old project
    try:
        content_item = get_deprecated_htmlstory_config(context)
        msg = ("\nYou've configured your HTML story in the 'values' worksheet. "
                "Don't do this. It will work for now, but may stop working "
                "soon. Instead, configure it in the 'p2p_content_items' "
                "worksheet.")
        puts(colored.red(msg))
        p2p_publish_htmlstory(content_item, site, s3)

    except KeyError:
        # This is fine. Actually preferred. There shouldn't be anything
        # P2P-related
        pass

    try:
        content_items = context[CONTENT_ITEMS_WORKSHEET]
    except KeyError:
        # No worksheet with the P2P content item configuration.  Fail!
        msg = ("\nYou need a worksheet named {0} in your Tarbell spreadsheet "
               "to publish P2P content items").format(CONTENT_ITEMS_WORKSHEET)
        puts(colored.red(msg))
        return

    for i, content_item in enumerate(content_items):
        try:
            content_type = content_item['content_type']
        except KeyError:
            msg = ("\nYou need to specify a content type for P2P content "
                    "item {0}").format(i)
            continue

        try:
            if content_type == 'blurb':
                p2p_publish_blurb(content_item, site, s3)

            elif content_type == 'htmlstory':
                p2p_publish_htmlstory(content_item, site, s3)

            else:
                msg = ("\nUnknown content type '{0}' for P2P content "
                       "item {1}. Skipping publication.").format(content_type, i)
                puts(colored.yellow(msg))
                continue

        except MissingP2PContentItemFieldError as e:
            # The spreadsheet is missing a field needed to publish. Fail
            # gracefully.
            msg = ("\nYou need to specify field '{0}' for P2P content "
                    "item {1}. Skipping publication.").format(e.field_name, i)
            puts(colored.yellow(msg))
            continue

        except TemplateNotFound:
            msg = ("\nCould not find template '{0}' for P2P content "
                   "item {1}. Skipping publication").format(
                       content_item['template'], i)
            puts(colored.yellow(msg))
            continue
    create_unfuddle_project,
    newproject_add_excludes,
    newproject_add_default_omniture_config,
    merge_extra_context,
    update_facebook,
)

NAME = "Tribune Off-Platform Tarbell Blueprint, version 2"

blueprint = TribuneTarbellBlueprint('blueprint', __name__)


try:
    locale.setlocale(locale.LC_ALL, 'en_US')
except locale.Error:
    puts(colored.red("Locale error"))



NEWPROJECT_HOOKS = (
    copy_front_end_build_script_templates,
    create_front_end_files,
    create_readme,
    create_unfuddle_project,
    newproject_add_excludes,
    newproject_add_default_omniture_config,
)

GENERATE_HOOKS = (
    merge_extra_context,
)