Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Last active August 24, 2017 22:25
Show Gist options
  • Save jefftriplett/bb527abd597fb6e68ec290fa8a33ced5 to your computer and use it in GitHub Desktop.
Save jefftriplett/bb527abd597fb6e68ec290fa8a33ced5 to your computer and use it in GitHub Desktop.
"""
# get these fromhttps://apps.twitter.com/
$ export TWITTER_ACCESS_TOKEN_KEY=''
$ export TWITTER_ACCESS_TOKEN_SECRET=''
$ export TWITTER_CONSUMER_KEY=''
$ export TWITTER_CONSUMER_SECRET=''
$ pip install click tweepy
$ python count_hashtags.py '#djangocon' 2017-08-08
"""
import click
import tweepy
from envparse import env
@click.command()
@click.argument('hashtag')
@click.argument('since_date')
def main(hashtag, since_date):
auth = tweepy.OAuthHandler(
env('TWITTER_CONSUMER_KEY'),
env('TWITTER_CONSUMER_SECRET')
)
auth.set_access_token(
env('TWITTER_ACCESS_TOKEN_KEY'),
env('TWITTER_ACCESS_TOKEN_SECRET')
)
count = 0
api = tweepy.API(auth)
tweets = tweepy.Cursor(
api.search,
q=hashtag,
since=since_date
).items()
for tweet in tweets:
print(tweet.text)
count += 1
print(count)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment