Live Twitter Data
Generate an API Key
#See https://docs.deepnote.com/environment/environment-variables for information on how to add you own API key
import os
twitter_api_token = os.getenv('TWITTER_KEY') # See https://docs.deepnote.com/environment/environment-variables for more information
Number of Mentions
username
Top Tweets Today
You can use the API to keep up with trends and find Tweets that you should follow up on or respond to.
query
starting_date = pd.Timestamp.now() - pd.Timedelta(1,'D')
starting_date = starting_date.floor('S').isoformat() + 'Z' # Reformat in a form that Twitter wants
# Search the Tweets
df = search_tweets(query, starting_date)
# Extract and sort by # of likes
def get_likes(x):
return x.get('like_count')
df['nlikes'] = df.public_metrics.apply(get_likes)
df = df.sort_values('nlikes',ascending=False)