def metadata_annotation(entry): subject = ellipse_text(entry.title, 128) return { "type": 'net.app.core.broadcast.message.metadata', "value": { "subject": subject } }
def instagram_format_for_adn(feed, entry): max_chars = MAX_CHARS - len(entry.link) + 1 post_text = ellipse_text(entry.title, max_chars) post_text += ' ' + entry.link post = { 'text': post_text, 'annotations': [cross_post_annotation(entry.link), image_annotation_for_entry(entry)] } return post
def format_for_adn(feed, entry): post_text = entry.title links = [] summary_text = '' if feed.include_summary: summary_text = strip_html_tags(entry.summary) sentances = list(splitter.split(summary_text)) sentances.reverse() summary_text = sentances.pop() while len(summary_text) <= 200: try: next_sentance = sentances.pop() except IndexError: break if len(summary_text + ' ' + next_sentance) <= 200: summary_text += ' ' + next_sentance summary_text = ellipse_text(summary_text, 200) if entry.feed_item: link = get_link_for_item(feed, entry.feed_item) else: link = entry.link link = iri_to_uri(link) link = append_query_string(link, params={'utm_source': 'PourOver', 'utm_medium': 'App.net'}) # If viewing feed from preview don't shorten urls preview = getattr(feed, 'preview', False) has_own_bitly_creds = feed.bitly_login and feed.bitly_api_key if has_own_bitly_creds or feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: if not has_own_bitly_creds: feed.bitly_login = '******' feed.bitly_api_key = 'R_a1311cd1785b7da2aedac9703656b0f1' short_url = yield get_short_url(entry, link, feed) if short_url: link = short_url # Starting out it should be as long as it can be max_chars = MAX_CHARS max_link_chars = 40 ellipse_link_text = ellipse_text(link, max_link_chars) # If the link is to be included in the text we need to make sure we reserve enough space at the end if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: max_chars -= len(' ' + ellipse_link_text) # Should be some room for a description if len(post_text) < (max_chars - 40) and summary_text: post_text = u'%s\n%s' % (post_text, summary_text) post_text = ellipse_text(post_text, max_chars) if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: post_text += ' ' + ellipse_link_text if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: links.insert(0, (link, ellipse_link_text)) else: links.insert(0, (link, entry.title)) link_entities = [] index = 0 for href, link_text in links: # logger.info('Link info: %s %s %s', post_text, link_text, index) text_index = post_text.find(link_text, index) if text_index > -1: link_entities.append({ 'url': href, 'text': link_text, 'pos': text_index, 'len': len(link_text), }) index = text_index post = { 'text': post_text, 'annotations': [cross_post_annotation(link)] } if link_entities: post['entities'] = { 'links': link_entities, } # logger.info('Info %s, %s', include_thumb, self.thumbnail_image_url) if feed.include_thumb and entry.thumbnail_image_url: post['annotations'].append(image_annotation_for_entry(entry)) if feed.include_video and entry.video_oembed: oembed = entry.video_oembed oembed['embeddable_url'] = entry.link post['annotations'].append({ "type": "net.app.core.oembed", "value": oembed }) lang = get_language(entry.language) if lang: post['annotations'].append({ "type": "net.app.core.language", "value": { "language": lang, } }) if entry.author: post['annotations'].append({ "type": "net.app.pourover.item.author", "value": { "author": entry.author, } }) if entry.tags: post['annotations'].append({ "type": "net.app.pourover.item.tags", "value": { "tags": entry.tags, } }) raise ndb.Return(post)
def format_for_adn(feed, entry): post_text = entry.title links = [] summary_text = '' if feed.include_summary: summary_text = strip_html_tags(entry.summary) sentances = list(splitter.split(summary_text)) sentances.reverse() summary_text = sentances.pop() while len(summary_text) <= 200: try: next_sentance = sentances.pop() except IndexError: break if len(summary_text + ' ' + next_sentance) <= 200: summary_text += ' ' + next_sentance summary_text = ellipse_text(summary_text, 200) link = format_link_for_entry(feed, entry) has_own_bitly_creds = feed.bitly_login and feed.bitly_api_key if has_own_bitly_creds or feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: if not has_own_bitly_creds: feed.bitly_login = '******' feed.bitly_api_key = 'R_a1311cd1785b7da2aedac9703656b0f1' short_url = yield get_short_url(entry, link, feed) if short_url: link = short_url # Starting out it should be as long as it can be max_chars = MAX_CHARS max_link_chars = 40 ellipse_link_text = ellipse_text(link, max_link_chars) # If the link is to be included in the text we need to make sure we reserve enough space at the end if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: max_chars -= len(' ' + ellipse_link_text) # Should be some room for a description if len(post_text) < (max_chars - 40) and summary_text: post_text = u'%s\n%s' % (post_text, summary_text) post_text = ellipse_text(post_text, max_chars) if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: post_text += ' ' + ellipse_link_text if feed.format_mode == FORMAT_MODE.TITLE_THEN_LINK: links.insert(0, (link, ellipse_link_text)) else: links.insert(0, (link, entry.title)) link_entities = [] index = 0 for href, link_text in links: # logger.info('Link info: %s %s %s', post_text, link_text, index) text_index = post_text.find(link_text, index) if text_index > -1: link_entities.append({ 'url': href, 'text': link_text, 'pos': text_index, 'len': len(link_text), }) index = text_index post = { 'text': post_text, 'annotations': [cross_post_annotation(link)] } if link_entities: post['entities'] = { 'links': link_entities, } # logger.info('Info %s, %s', include_thumb, self.thumbnail_image_url) if feed.include_thumb and entry.thumbnail_image_url: post['annotations'].append(image_annotation_for_entry(entry)) if feed.include_video and entry.video_oembed: oembed = entry.video_oembed oembed['embeddable_url'] = entry.link post['annotations'].append({ "type": "net.app.core.oembed", "value": oembed }) post['annotations'] += common_annotations(entry) raise ndb.Return(post)