Skip to content

Instantly share code, notes, and snippets.

@SIRHAMY
Created April 21, 2016 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SIRHAMY/237bc3928e535e55ab49dabfa30acdb0 to your computer and use it in GitHub Desktop.
Save SIRHAMY/237bc3928e535e55ab49dabfa30acdb0 to your computer and use it in GitHub Desktop.
import time
import tweetpony
self.twitAPI = tweetpony.API(consumer_key = env.TWITTER_CONSUMER_KEY,
consumer_secret = env.TWITTER_CONSUMER_SECRET,
access_token = env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret = env.TWITTER_ACCESS_TOKEN_SECRET)
#Abstract minefeed so you can recall it if there's an error
def mineFeed(self, twitterID):
print("Fetching feed...")
try:
userFeed = self.twitAPI.user_timeline(user_id=str(int(twitterID)), exclude_replies="true", include_rts="false" )
storeFeed(twitterID, userFeed)
except Exception as err:
if('88' in str(err)):
print("Mining Suspended: Reached Twitter rate limit")
print("Waiting 3 minutes then retrying...")
time.sleep(180)
self.mineFeed( twitterID) #Call function again after timeout
else:
print("ERROR: Something broke when fetching the feed")
print str(err)
else:
print("Fetch sucessful.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment