Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.4 kB
2
Indexable
import tweepy
import pandas as pd

consumer_key = 'tftp08o1jrO8igUZzOkXJfNFT'
consumer_secret = 'uAKMzR5U7XPo8qtI0F5Dku2OQqsp8okt8xbKTWG4qGq0fzDIw0'

access_token = '901399260729454592-QB9NJtXxKrdY6rHNFQCWUPbkwBycb7y'
access_token_secret = 'PHJuk4iPXEFQOzE3FglbnxhYDyuDcj8patgSRqsXl3EcW'

auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit= True)

users = ['Bitcoin Magazine']

for user in users:
    tweet_text = []
    tweet_created = []
    user_name = []
    user_created = []
    user_followers = []
    tweet_hashtags = []

    for i in tweepy.Cursor(api.user_timeline, screen_name = user, tweet_mode= "extended").items(5000):
        tweet_text.append(i.full_text)
        tweet_created.append(i.created_at)
        user_name.append(i.user.screen_name)
        user_created.append(i.user.created_at)
        user_followers.append(i.user.followers_count)
        tweet_hashtags.append([h['text'].strip() for h in i.entities['hashtags']])
    
    user_data = pd.DataFrame({'user_name':user_name, 'user_created':user_created, 'user_followers':user_followers,
                         'date':tweet_created, 'text':tweet_text, 'hashtags': tweet_hashtags})
    
    user_data.to_csv('test_data/' + user + '.csv', index=False)

    print(user)