In this assignment you will read and process Twitter data. A starting file titled assignments.py is provided to you and can be found at the course's GitHub page, and you will fill in the missing parts. You will need a small JSON file called keys.json
at the same level, that contains your Twitter access information, as described in the notes. Make sure you have done so before you proceed. Running the first 48 lines of the script in your Python 3 interpreter should tell you if it works OK or not.
You should be looking at the assignment1.py file as you read along.
The first 67 lines of the script read from Twitter and create a list called "tweets" for you. You should not change these lines, and your answers in the rest of the file will make use of the "tweets" variable. This contains all tweets that mention the words "Hanover" and "College", and it is limited to the last 8 or so days, as Twitter does not allow us to go further back in queries.
full_text
that contains the text of the tweet.full_text
entry doesn't actually contain the full tweet, but only an abbreviated version. You can see this in some of the texts you extracted, which probably ended in ellipses. To fix this, first write a function get_full_text
that is given a tweet and returns the full tweet text as follows:
retweeted_status
key/field present, then the tweet text is indeed in the full_text
list as above.retweeted_status
, and look at its full_text
field.tags_per_tweet
.hashtags
. Its keys would be the different hashtags, and the value for a hashtag is the number of times that tag occurred in the tweets. Implementing this will probably require a double iteration over the list of tags_per_tweet
.sorted
function appropriately will get you partway there.tag_info
.tag_info
to a JSON string and write it to a file called tag_info.json
. You could paste your result in this site to make sure it worked.text
with value the string text of the tweet.author
with value the string handle/screen name of the tweet's authordate
with value the string date when the tweet was createdhashtags
with value a list of the string hashtags in the tweetmentions
with value a list of the string handles of the users mentioned in the tweetsimpler_tweets.json
.You should submit your completed Python file as an email attachment to me. The name of the file should include your first and last name, in addition to the assignment's number. It should contain no whitespaces.