Skip to content

Instantly share code, notes, and snippets.

@Joshuaek
Created November 5, 2017 21:07
Show Gist options
  • Save Joshuaek/1a0e293a488b5186b87abe9eb6682fd1 to your computer and use it in GitHub Desktop.
Save Joshuaek/1a0e293a488b5186b87abe9eb6682fd1 to your computer and use it in GitHub Desktop.
import tweepy
import json
import datetime
import time
# API access details - get yours from Twitter
access_token = "********************"
access_token_secret = "********************"
consumer_key = "********************"
consumer_secret = "********************"
#Authenticate to Twitter api using our account keys
auth_details = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_details.set_access_token(access_token, access_token_secret)
#Create connection to the Twitter api
api = tweepy.API(auth_details)
#Loop and sleep to download tweets
for x in range(0,24):
tweet_array = []
tweets = api.home_timeline(count=100)
for tweet in tweets:
t = {"text" : tweet.text, "likes": tweet.favorite_count, "retweets": tweet.retweet_count }
tweet_array.append(t)
d = datetime.datetime.today().strftime('%Y-%m-%d-%H-%M-%s')
f = open('tweets-' + d + ".json", 'w')
f.write(json.dumps(tweet_array))
f.close()
print("Sleeping")
time.sleep(60 * 30)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment