Created
November 5, 2017 21:07
-
-
Save Joshuaek/1a0e293a488b5186b87abe9eb6682fd1 to your computer and use it in GitHub Desktop.
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 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