-
-
Save szwinter/1dea5a932b4b6d7bf1a9e3990df5e2a2 to your computer and use it in GitHub Desktop.
A Python script to download all the tweets of a hashtag into a csv
This file contains hidden or 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 | |
| import pandas as pd | |
| ####input your credentials here | |
| consumer_key = '' | |
| consumer_secret = '' | |
| access_token = '' | |
| access_token_secret = '' | |
| 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) | |
| #####United Airlines | |
| # Open/Create a file to append data | |
| csvFile = open('ua.csv', 'a') | |
| #Use csv Writer | |
| csvWriter = csv.writer(csvFile) | |
| for tweet in tweepy.Cursor(api.search,q="#unitedAIRLINES",count=100, | |
| lang="en", | |
| since="2017-04-03").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