Parsing Twitter tweets

Being in the offensive security domain, we might wonder why we need to parse Twitter tweets. This question is valid, as this use case is more suited to defensive security. It may help, however, to uncover a good amount of information if we are targeting a specific individual or a specific organization.

As mentioned earlier, Twitter-tweet-parsing can be used by cyber intelligence teams to see if any defamation or sensitive content has been posted under the organization's name. Let's take a look at the following example that explains Twitter tweet parsing. First, we need to install the Python module as follows:

pip3 install tweet_parser

Our example takes a Twitter feed as an input JSON file and parses all tweets to produce the output. Let's create a file called sample.py as shown:

Let's use a sample Twitter feed file called exp.json as follows:

Next, run the code to print all the tweets as follows:

The Twitter class object created in line 14, tweet=Tweet(tweet_dict), has many other methods and variables that can give granular information about tweets such as the date, time, likes, and retweets. The different supported methods can be obtained by running dir(tweet), the output of which is given as follows:

['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'all_text', 'bio', 'clear', 'copy', 'created_at_datetime', 'created_at_seconds', 'created_at_string', 'embedded_tweet', 'favorite_count', 'follower_count', 'following_count', 'fromkeys', 'generator', 'geo_coordinates', 'get', 'gnip_matching_rules', 'hashtags', 'id', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'in_reply_to_user_id', 'items', 'keys', 'klout_id', 'klout_influence_topics', 'klout_interest_topics', 'klout_profile', 'klout_score', 'lang', 'media_urls', 'most_unrolled_urls', 'name', 'original_format', 'poll_options', 'pop', 'popitem', 'profile_location', 'quote_count', 'quote_or_rt_text', 'quoted_tweet', 'retweet_count', 'retweeted_tweet', 'screen_name', 'setdefault', 'text', 'tweet_links', 'tweet_type', 'update', 'user_entered_text', 'user_id', 'user_mentions', 'values']
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.240.142