Created
July 9, 2019 18:12
-
-
Save s1db/7609d4c0185de3a773337172b08bf37e to your computer and use it in GitHub Desktop.
Python Twitter Hashtag Data Collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tweepy | |
import csv | |
# assuming twitter_authentication.py contains each of the 4 oauth elements (1 per line) | |
from twitter_authentication import API_KEY, API_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET | |
auth = tweepy.OAuthHandler(API_KEY, API_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
api = tweepy.API(auth,wait_on_rate_limit=True) | |
csvFile = open('antivacc.csv', 'a') | |
#Use csv Writer | |
csvWriter = csv.writer(csvFile) | |
for tweet in tweepy.Cursor(api.search,q="#antivaccine",count=100, | |
lang="en", | |
since="2019-04-01", | |
until="2019-06-01").items(): | |
print (tweet.created_at, tweet.text) | |
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8')]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment