Notebook to demonstrate the tweet_parser module

Fiona Pigott


In [ ]:
# import the tweet_parser module
from tweet_parser.tweet import Tweet
import fileinput
import json

In [ ]:
# import the exact same set of Tweets in both original format and activity streams format
activity_streams_tweets = []
for line in fileinput.FileInput("../test/tweet_payload_examples/activity_streams_examples.json"):
    activity_streams_tweets.append(Tweet(json.loads(line)))

original_format_tweets = []
for line in fileinput.FileInput("../test/tweet_payload_examples/original_format_examples.json"):
    original_format_tweets.append(Tweet(json.loads(line)))

In [ ]:
print("Available methods: \n - {}".format("\n - ".join([x for x in activity_streams_tweets[0].__dir__() if x[0] != "_"])))

In [ ]:
activity_streams_tweets[-4].tweet_links

In [ ]:
for i,x in enumerate(activity_streams_tweets):
    print(x.id, x.tweet_type, x.tweet_links)

In [ ]:
for i,x in enumerate(original_format_tweets):
    print(i, ":", x.all_text)
    print("##########")

In [ ]:
quote_ception = original_format_tweets[2]

In [ ]:
quote_ception.hashtags

In [ ]:
for x in activity_streams_tweets:
    print(x.user_mentions_ids)
    print("##########")

In [ ]:
for x in activity_streams_tweets:
    print(x.all_text)
    print("##########")

In [ ]:
activity_streams_tweets[16].quoted_user

In [ ]:
activity_streams_tweets[16].quote_tweet.user_mentions

In [ ]:
for i,x in enumerate(activity_streams_tweets):
    print(i,x.quoted_mentions)
    print("##########")

In [ ]:
for x in original_format_tweets:
    print(x.all_text_without_links)
    print("##########")

In [ ]:
for x in original_format_tweets:
    print(x.most_unrolled_urls)
    print("##########")

In [ ]:
for x in original_format_tweets:
    print(x.hashtags)
    print("##########")

In [ ]:
Tweet({"thing":"th"})

In [ ]:
malformed_quotetweet = Tweet(json.load(
            open("tweet_payload_examples/broken_and_unsupported_payloads/original_format_missing_quotetweet_field.json","r")),
                                do_format_checking = True)

In [ ]:
malformed_quotetweet.embedded_tweet

In [ ]: