Beispiel #1
0
    def tweet_type(self):
        """
        The type of Tweet this is (3 options: tweet, quote, and retweet)

        Returns:
            str: ("tweet","quote" or "retweet" only)
            value returned by calling `tweet_text.get_tweet_type` on `self`
        """
        return tweet_text.get_tweet_type(self)
Beispiel #2
0
def get_entities(tweet):
    """
    Helper function to simply grabbing the entities. \n
    Caveat: In the case of Retweets, a Retweet is stored as
    "RT @someone: Some awesome status". In the case where pre-appending
    the string "RT @someone:" causes the Tweet to exceed 140 characters,
    entites (hashtags, mentions, urls) beyond the 140 character mark are
    excluded from the Retweet's entities. This seems like counterintuitive
    behavior, so we ensure here that the entities of a Retweet are a
    superset of the entities of the Retweeted status.

    Args:
        tweet (Tweet or dict): Tweet in question

    Returns:
        dict: dictionary of potential entities.

    Example:
        >>> from tweet_parser.getter_methods.tweet_entities import get_entities
        >>> original = {"created_at": "Wed May 24 20:17:19 +0000 2017",
        ...             "entities": {"user_mentions": [{
        ...                              "indices": [14,26], #characters where the @ mention appears
        ...                              "id_str": "2382763597", #id of @ mentioned user as a string
        ...                              "screen_name": "notFromShrek", #screen_name of @ mentioned user
        ...                              "name": "Fiona", #display name of @ mentioned user
        ...                              "id": 2382763597 #id of @ mentioned user as an int
        ...                            }]
        ...                          }
        ...             }
        >>> get_entities(original)
        {'user_mentions': [{'indices': [14, 26], 'id_str': '2382763597', 'screen_name': 'notFromShrek', 'name': 'Fiona', 'id': 2382763597}]}
        """

    entity_key = "entities" if is_original_format(
        tweet) else "twitter_entities"
    if get_tweet_type(tweet) == "retweet":
        retweet_entities = tweet.get(entity_key, [])
        all_entities = get_retweeted_tweet(tweet).get(entity_key, []).copy()
        # the only thing that the Retweet will have that the Retweeted Tweet
        # won't have is the @-mention of the RTd user at the front ("RT @someone:")
        # I'm going to add that in, so the the Retweet's entities are a superset
        # of the RTd Tweet's entites
        all_entities["user_mentions"] = (
            [retweet_entities["user_mentions"][0]] +
            all_entities["user_mentions"])
        return all_entities
    else:
        return tweet.get(entity_key, [])
Beispiel #3
0
def get_retweeted_tweet(tweet):
    """
    Get the retweeted Tweet and return it as a dictionary
    If the Tweet is not a Retweet, return None

    Args:
        tweet (Tweet or dict): A Tweet object or a dictionary

    Returns:
        dict: A dictionary representing the retweeted status
        or None if there is no quoted status. \n
        - For original format, this is the value of "retweeted_status" \n
        - For activity streams, If the Tweet is a Retweet this is the value of the key "object"
    """
    if get_tweet_type(tweet) == "retweet":
        if is_original_format(tweet):
            return tweet["retweeted_status"]
        else:
            return tweet["object"]
    else:
        return None
Beispiel #4
0
 def tweet_type(self):
     """
     3 options: tweet, quote, and retweet
     """
     return tweet_text.get_tweet_type(self)