Skip to content

Instantly share code, notes, and snippets.

@mramirid
Last active January 7, 2023 02:09
Show Gist options
  • Save mramirid/72626329c5b815cf4789e7ff7a0ec223 to your computer and use it in GitHub Desktop.
Save mramirid/72626329c5b815cf4789e7ff7a0ec223 to your computer and use it in GitHub Desktop.
Twitter API - request tweets by hastag
import tweepy
import csv
# 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)
# Open/Create a file to append data
csvFile = open('golang.csv', 'a')
# Use csv Writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search, q="#golang", count=20, lang="en", since="2020-03-30").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