Example #1
0
  def activity_to_salmon_vars(self, activity):
    """Extracts Salmon template vars from a JSON activity.

    https://developers.google.com/+/api/latest/activies#resource

    Args:
      activity: JSON dict

    Returns: dict of template vars for ATOM_SALMON_TEMPLATE
    """
    actor = activity.get('actor', {})
    content = activity.get('object', {}).get('content')
    title = activity.get('title')

    # find the attached link, if any
    link = None
    for attachment in activity.get('object', {}).get('attachments', []):
      if attachment.get('objectType') == 'article':
        link = attachment.get('url')

    vars = {
      'id': util.tag_uri(self.DOMAIN, activity.get('id')),
      'author_name': actor.get('displayName'),
      'author_uri': 'acct:%[email protected]' % actor.get('id'),
      'in_reply_to': link,
      'content': content,
      'title': title if title else content,
      'updated': activity.get('published'),
      }

    return vars
Example #2
0
  def post_to_salmon_vars(self, post):
    """Extracts Salmon template vars from a JSON Facebook post or comment.

    Args:
      post: JSON dict

    Returns: dict of template vars for ATOM_SALMON_TEMPLATE
    """
    post_from = post.get('from', {})
    return {
      'id': util.tag_uri(self.DOMAIN, post.get('id')),
      'author_name': post_from.get('name'),
      'author_uri': 'acct:%[email protected]' % post_from.get('id'),
      'in_reply_to': post.get('link'),
      'content': post.get('message'),
      'title': post.get('message'),
      'updated': post.get('created_time'),
      }
Example #3
0
  def tweet_to_salmon_vars(self, tweet):
    """Extracts Salmon template vars from a JSON tweet.

    Args:
      tweet: JSON dict

    Returns: dict of template vars for ATOM_SALMON_TEMPLATE
    """
    # there might be more than one URL in the tweet. find the one on our domain.
    # https://dev.twitter.com/docs/tweet-entities
    link = None
    for url_data in tweet.get('entities', {}).get('urls', []):
      # expanded_url isn't always provided
      url = url_data.get('expanded_url') or url_data.get('url')
      if url and urlparse.urlparse(url).netloc == self.key().name():
        link = url

    # parse the timestamp, formatted e.g. 'Sun, 01 Jan 2012 11:44:57 +0000'
    created_at = tweet.get('created_at')
    if created_at:
      created_at = re.sub(' \+[0-9]{4}$', '', created_at)
      updated = datetime.datetime.strptime(created_at,
                                           '%a, %d %b %Y %H:%M:%S')
      updated = updated.isoformat()
    else:
      updated = ''

    return {
      'id': util.tag_uri(self.DOMAIN, str(tweet.get('id'))),
      'author_name': tweet.get('from_user_name'),
      'author_uri': 'acct:%[email protected]' % tweet.get('from_user'),
      'in_reply_to': link,
      'content': tweet.get('text'),
      'title': tweet.get('text'),
      'updated': updated,
      }
def tag_uri(name):
  return util.tag_uri('instagram.com', name)
def tag_uri(name):
  return util.tag_uri('facebook.com', name)
 def tag_uri(self, name):
   """Returns a tag URI string for this source and the given string name."""
   return util.tag_uri(self.DOMAIN, name)
def tag_uri(name):
  return util.tag_uri('twitter.com', name)