Skip to content

Instantly share code, notes, and snippets.

@alfard
Last active August 29, 2015 13:58
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 alfard/15bd8c58df93af548dd2 to your computer and use it in GitHub Desktop.
Save alfard/15bd8c58df93af548dd2 to your computer and use it in GitHub Desktop.
History_tweet
import tweepy
import time
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)
a=[]
page_count = 0
for tweet in tweepy.Cursor(api.search,
q="NKM",
count=25,
result_type="recent",
include_entities=True,
lang="fr").items():
page_count += 1
#Enregistrement dans la matrice a des tweets
a.append([tweet.created_at,tweet.text])
print len(a)
time.sleep(0.2)
#Pour respecter la fréquence imposée par l'api, je fais une pause de 0.2 secondes entre
#chaque résultat
if tweepy.TweepError is "[{u'message': u'Over capacity', u'code': 130}]":
print "Over capacity"
time.sleep(2000)
if tweepy.TweepError is "[{u'message': u'Internal error', u'code': 131}]":
print "Internal error"
time.sleep(2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment