Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tweepy as tw
- import pandas as pd
- from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
- import twittercredentials
- import re
- auth = tw.OAuthHandler(twittercredentials.CONSUMER_KEY, twittercredentials.CONSUMER_SECRET)
- auth.set_access_token(twittercredentials.ACCESS_TOKEN, twittercredentials.ACCESS_TOKEN_SECRET)
- api = tw.API(auth, wait_on_rate_limit=True)
- search_word = 'cybertruck'
- date_since = "2019-10-20"
- tweets = tw.Cursor(api.search, q=search_word, lang="en", tweet_mode='extended', since=date_since).items(50)
- # geomethods = tw.Cursor(api.reverse_geocode).items(50)
- text_file = open('tweets.txt', 'w')
- # text_file.write(tweets)
- for i in tweets:
- a = {}
- # b = []
- a['Tweet'] = i.full_text
- a['Location'] = i.user.location
- # a.update({'Tweet': i.full_text})
- print(a)
- text_file.write(str(a))
- text_file.write("\n")
- # b.append([i.full_text, i.user.location])
- # b.append("\n")
- # print(a)
- # text_file.write(str(b))
- # text_file.write("\n")
- # print(a)
- # df = pd.read_table('tweets.txt')
- # print(df)
- # print(a)
- # print(i.full_text)
- # print(i.coordinates)
- # print(i.user.location)
- # text_file.write(i.full_text)
- # text_file.write(i.user.location)
- # text_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement