I am trying to mine data in a local area.
First I would like to Twython to search all tweets on twitter to find those tweets that contain a particular keyword, and then print those tweets. I have successfully written the few lines of code that do this:
from twython import Twython
TWITTER_APP_KEY = ''
TWITTER_APP_KEY_SECRET = ''
TWITTER_ACCESS_TOKEN = ''
TWITTER_ACCESS_TOKEN_SECRET = ''
t = Twython(TWITTER_APP_KEY, TWITTER_APP_KEY_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET)
search = t.search(q='hello', count=100)
tweets = search['statuses']
for tweet in tweets:
print (tweet['text'], '\n')
Next, I want to generate the user name of the ID that tweeted the text (not just the ID but the actual username), and print it.
After this, I would like to generate the friends list of the particular user, and print it.
How can I get the user name and the friends list?
To generate the username, you can look in the "user" section of each status. There will be a key called "screen_name" and its value is what you'll need.
In the user section, there is also an "id". You'll need to create a separate call using this id to get that user's followers. The twitter api (and twython) supports getting followers from an id. See https://dev.twitter.com/docs/api/1.1/get/followers/ids