示例#1
0
    def setUp(self):
        self.content_item_slug = 'chi-na-lorem-a'
        self.collection_slug = 'chi_na_lorem'
        self.p2p = get_connection()
        self.p2p.debug = True
        self.p2p.config['IMAGE_SERVICES_URL'] = \
            'http://image.p2p.tribuneinteractive.com'
        self.maxDiff = None

        self.content_item_keys = (
            'altheadline', 'expire_time',
            'canonical_url', 'mobile_title', 'create_time',
            'source_name', 'last_modified_time', 'seodescription',
            'exclusivity', 'content_type_group_code', 'byline',
            'title', 'dateline', 'brief', 'id', 'web_url', 'body',
            'display_time', 'publish_time', 'undated', 'is_opinion',
            'columnist_id', 'live_time', 'titleline',
            'ad_exclusion_category', 'product_affiliate_code',
            'content_item_state_code', 'seo_redirect_url', 'slug',
            'content_item_type_code', 'deckheadline', 'seo_keyphrase',
            'mobile_highlights', 'subheadline', 'thumbnail_url',
            'source_code', 'ad_keywords', 'seotitle', 'alt_thumbnail_url')
        self.collection_keys = (
            'created_at', 'code', 'name',
            'sequence', 'max_elements', 'productaffiliatesection_id',
            'last_modified_time', 'collection_type_code',
            'exclusivity', 'id')
        self.content_layout_keys = (
            'code', 'items', 'last_modified_time', 'collection_id', 'id')
        self.content_layout_item_keys = (
            'content_item_type_code', 'content_item_state_code',
            'sequence', 'headline', 'abstract',
            'productaffiliatesection_id', 'slug', 'subheadline',
            'last_modified_time', 'contentitem_id', 'id')
示例#2
0
    def setUp(self):
        self.content_item_slug = 'chi-na-lorem-a'
        self.collection_slug = 'chi_na_lorem'
        self.second_collection_slug = 'chi_na_lorem_ispum'

        self.p2p = get_connection()
        self.p2p.debug = True
        self.p2p.config['IMAGE_SERVICES_URL'] = \
            'http://image.p2p.tribuneinteractive.com'
        self.maxDiff = None

        self.content_item_keys = (
            'altheadline', 'expire_time', 'canonical_url', 'mobile_title',
            'create_time', 'source_name', 'last_modified_time',
            'seodescription', 'exclusivity', 'content_type_group_code',
            'byline', 'title', 'dateline', 'brief', 'id', 'web_url', 'body',
            'display_time', 'publish_time', 'undated', 'is_opinion',
            'columnist_id', 'live_time', 'titleline', 'ad_exclusion_category',
            'product_affiliate_code', 'content_item_state_code',
            'seo_redirect_url', 'slug', 'content_item_type_code',
            'deckheadline', 'seo_keyphrase', 'mobile_highlights',
            'subheadline', 'thumbnail_url', 'source_code', 'ad_keywords',
            'seotitle', 'alt_thumbnail_url')
        self.collection_keys = ('created_at', 'code', 'name', 'sequence',
                                'max_elements', 'productaffiliatesection_id',
                                'last_modified_time', 'collection_type_code',
                                'exclusivity', 'id')
        self.content_layout_keys = ('code', 'items', 'last_modified_time',
                                    'collection_id', 'id')
        self.content_layout_item_keys = ('content_item_type_code',
                                         'content_item_state_code', 'sequence',
                                         'headline', 'abstract',
                                         'productaffiliatesection_id', 'slug',
                                         'subheadline', 'last_modified_time',
                                         'contentitem_id', 'id')
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)))
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."))
示例#5
0
 def setUp(self):
     self.content_item_slug = 'la-na-lorem-a'
     self.collection_slug = 'la_na_lorem'
     self.p2p = get_connection()
     self.p2p.debug = True
     self.maxDiff = None
示例#6
0
 def setUp(self):
     self.content_item_slug = 'chi-na-lorem-a'
     self.collection_slug = 'chi_na_lorem'
     self.p2p = get_connection()
     self.p2p.debug = True
     self.maxDiff = None
示例#7
0
class BaseP2PTest(unittest.TestCase):
    content_item_keys = (
        'altheadline', 'expire_time',
        'canonical_url', 'mobile_title', 'create_time',
        'source_name', 'last_modified_time', 'seodescription',
        'exclusivity', 'content_type_group_code', 'byline',
        'title', 'dateline', 'brief', 'id', 'web_url', 'body',
        'display_time', 'publish_time', 'undated', 'is_opinion',
        'columnist_id', 'live_time', 'titleline',
        'ad_exclusion_category', 'product_affiliate_code',
        'content_item_state_code', 'seo_redirect_url', 'slug',
        'content_item_type_code', 'deckheadline', 'seo_keyphrase',
        'mobile_highlights', 'subheadline', 'thumbnail_url',
        'source_code', 'ad_keywords', 'seotitle', 'alt_thumbnail_url'
    )
    collection_keys = (
        'created_at', 'code', 'name',
        'sequence', 'max_elements', 'productaffiliatesection_id',
        'last_modified_time', 'collection_type_code',
        'exclusivity', 'id'
    )
    content_layout_keys = (
        'code', 'items', 'last_modified_time', 'collection_id', 'id'
    )
    content_layout_item_keys = (
        'content_item_type_code', 'content_item_state_code',
        'sequence', 'headline', 'abstract',
        'productaffiliatesection_id', 'slug', 'subheadline',
        'last_modified_time', 'contentitem_id', 'id'
    )
    p2p = get_connection()
    test_story_slugs = ["la-test-p2p-python-temp-story-%s" % x for x in range(0, 8)]
    first_test_story_slug = "la-test-p2p-python-temp-story-0"
    test_htmlstory_slug = "la-test-p2p-python-temp-htmlstory"
    test_photo_slug = "la-test-p2p-python-temp-photo"
    test_collection_codes = ["la-test-p2p-python-collection-%s" % x for x in range(0, 3)]
    first_test_collection_code = "la-test-p2p-python-collection-0"
    second_test_collection_code = "la-test-p2p-python-collection-1"

    @classmethod
    def setUpTestStories(cls):
        # Create a bunch of test stories and store to self.test_story_slugs
        for slug in cls.test_story_slugs:
            cls.p2p.create_or_update_content_item({
                "slug": slug,
                "content_item_type_code": "story",
                "title": "Temporary content item #%s for unittesting" % slug,
                "body": "Placeholder body for %s" % slug
            })


    @classmethod
    def setUpTestHTMLStories(cls):
        # Create a test htmlstory
        cls.p2p.create_or_update_content_item({
            "slug": cls.test_htmlstory_slug,
            "content_item_type_code": "htmlstory",
            "title": "Temporary htmlstory for unittesting",
            "body": "Placeholder body for the htmlstory"
        })

    @classmethod
    def setUpTestPhoto(cls):
        # Create a test htmlstory
        cls.p2p.create_or_update_content_item({
            "slug": cls.test_photo_slug,
            "content_item_type_code": "photo",
            "title": "Temporary photo for unittesting",
        })

    @classmethod
    def setUpTestCollections(cls):
        for slug in cls.test_collection_codes:
            try:
                cls.p2p.get_collection_layout(slug)
            except P2PNotFound:
                cls.p2p.create_collection({
                    'code': slug,
                    'name': 'Test collection #%s created via API' % slug,
                    'section_path': '/test'
                })

    def setUp(self):
        self.p2p.debug = True
        self.p2p.config['IMAGE_SERVICES_URL'] = 'http://image.p2p.tribuneinteractive.com'
示例#8
0
import p2p
import random

connection = p2p.get_connection()


def make_random_content():
    random_slug = "chi-ugc-relatedphoto-andre-bellos-interview%s-2013-06-24" % random.random()

    test_json = {
        "content_item_type_code": "photo",
        "display_time": "2013-06-24T19:15:53Z",
        "content_item_state_code": "live",
        "title": "Andre Bellos interview",
        "credit": "Posted By Andre Bellos, <a href='http://community.chicagotribune.com/'>Community  Contributor</a>",
        "caption": "Hollywood fun=)",
        "photo_upload": {"alt_thumbnail": {"url": "https://www.filepicker.io/api/file/JoypBj9YTyeL0UtXwARm?dl=false"}},
        "product_affiliate_code": "chinews",
        "source_code": "chicagotribuneugc",
        "slug": random_slug,
    }

    return test_json


print "About to hit p2p API with photo json"
random_content = make_random_content()
resp = connection.create_content_item(random_content)

print resp