<jupyter_start><jupyter_text>Data Mining Twittergithub.com/BALBOARC  Authenticating with Twitter Via Tweepy<jupyter_code>import tweepy
import keys
auth = tweepy.OAuthHandler(keys.consumer_key, 
                          keys.consumer_secret)
auth.set_access_token(keys.access_token,
                      keys.access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,
                 wait_on_rate_limit_notify=True)<jupyter_output><empty_output><jupyter_text>Getting Information About a Twitter Account<jupyter_code>nasa = api.get_user('nasa')
nasa.id
nasa.name
nasa.screen_name
nasa.description
nasa.status.text
nasa.followers_count
nasa.friends_count
me = api.me()
me.friends_count<jupyter_output><empty_output><jupyter_text>Introduction to Tweepy Cursors: Getting an Account’s Followers and Friends<jupyter_code>followers = []
cursor = tweepy.Cursor(api.followers, screen_name='nasa')
for account in cursor.items(10):
    followers.append(account.screen_name)
print('Followers:', 
      ' '.join(sorted(followers, key=lambda s: s.lower())))
# cursor = tweepy.Cursor(api.followers, screen_name='nasa', count=200)
# Determining Whom an Account Follows
friends = []
cursor = tweepy.Cursor(api.friends, screen_name='nasa')
for friend in cursor.items(10):
    friends.append(friend.screen_name)
print('Friends:', 
     ' '.join(sorted(friends, key=lambda s: s.lower())))
# Getting a User’s Recent Tweets
nasa_tweets = api.user_timeline(screen_name='nasa', count=3)
for tweet in nasa_tweets:
    print(f'{tweet.user.screen_name}: {tweet.text}\n')
# Grabbing Recent Tweets from Your Own Timeline
# api.home_timeline()<jupyter_output><empty_output><jupyter_text>Searching Recent Tweets<jupyter_code>from textblob import TextBlob
from tweetutilities import print_tweets
tweets = api.search(q='Mars Opportunity Rover', count=3)
print_tweets(tweets)
# Certifique-se que o TextBLob está instalado:
# pip install -U textblob
# python -m textblob.download_corpora (consegui utilizando o terminal do linux)<jupyter_output><empty_output><jupyter_text>Searching for a Hashtag<jupyter_code>tweets = api.search(q='#collegefootball', count=2)
print_tweets(tweets)<jupyter_output>I write essays and handle online classes at an affordable fee. 
Feel free to contact me for help. 

👑Brainywriters2… https://t.co/jUycP23K7E

RT @woodwardsports: Go Green! Go Blue! Just don’t root for you know who! 
#GoGreen #GoWhite #GoBlue #BuckOhioState #collegefootball #rivals…<jupyter_text>Spotting Trends: Twitter Trends API<jupyter_code>trends_available = api.trends_available()
len(trends_available)
trends_available[1]
# Worldwide Trending Topics
world_trends = api.trends_place(id=1)
trends_list = world_trends[0]['trends']
trends_list[0]
trends_list = [t for t in trends_list if t['tweet_volume']]
from operator import itemgetter
trends_list.sort(key=itemgetter('tweet_volume'), reverse=True)
for trend in trends_list[:5]:
    print(trend['name'])
# New York City Trending Topics
nyc_trends = api.trends_place(id=2459115) # New York City WOEID
nyc_list = nyc_trends[0]['trends']
nyc_list = [t for t in nyc_list if t['tweet_volume']]
nyc_list.sort(key=itemgetter('tweet_volume'), reverse=True)
for trend in nyc_list[:5]:
    print(trend['name'])<jupyter_output>spotify
<NAME>
apple
Cuomo
#CPAC2021<jupyter_text>Create a Word Cloud from Trending Topics<jupyter_code>topics = {}
for trend in nyc_list:
    topics[trend['name']] = trend['tweet_volume']
from wordcloud import WordCloud
wordcloud = WordCloud(width=800, height=600, prefer_horizontal=0.5, min_font_size=10, colormap='prism', background_color='black')
wordcloud = wordcloud.fit_words(topics)
wordcloud = wordcloud.to_file('TrendingTwitter.png')
from IPython.display import Image
Image('TrendingTwitter.png')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1110523532522475, 'fraction_numerical': 0.01110523532522475, 'mean_word_length': 6.67342799188641, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '598497', 'license': 'MIT', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1354, 'n_words': 279, 'path': 'TwitterAPI.ipynb', 'repo_name': 'BALBOARC/Twitter_API_Data', 'size': '3783'}