How to use the tweepy.Cursor function in tweepy

To help you get started, we’ve selected a few tweepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psychemedia / newt / biglistgrab.py View on Github external
tmp=api.lookup_users(screen_names=l)
  		for u in tmp:
  			twd.append(u)
  			twn.append(u.screen_name)
else: exit(-1)

for user in twn:
	currSampleSize=sampleSize
	source=user
	twd=[]
	fd='reports/'+fpath #+user+'/'
	
	fn=fd+user+'_fo_'+str(sampleSize)+'_'+now.strftime("_%Y-%m-%d-%H-%M-%S")+'.csv'
	print 'grabbing follower IDs for',user
	try:
		mi=tweepy.Cursor(api.followers_ids,id=user).items()
	except: 
		continue
	users=[]
	try:
		for m in mi: users.append(m)
	except: continue
	biglen=str(len(users))
	print 'Number of followers:',biglen
	#HACK
	if str(len(users))>10000: currSampleSize=10000
	#this breaks the date recreation on followers - need a run of 10000 users
	if currSampleSize>0:
		if len(users)>currSampleSize:
			if ORDEREDSAMPLE !=1:
				users=random.sample(users, currSampleSize)
				print 'Using a random sample of '+str(currSampleSize)+' from '+str(biglen)
github congosto / t-hoarder_kit / scripts / tweet_rest.py View on Github external
def get_following (user_keys,api,user,dict_friends,f_log,f_out,flag_friends):
  print 'Getting user following',user
  try:
    profile=api.get_user( screen_name=user)
    num_following=profile.friends_count
    if flag_friends:
      put_profile (api,user,profile,'root',f_log, f_out)
    following_getting=0
    try:
      print 'user: %s --> getting %s following profiles' % (user,num_following)
      for page in tweepy.Cursor(api.friends,screen_name=user,
                                count=200,
                                monitor_rate_limit=True, 
                                wait_on_rate_limit=True,
                                wait_on_rate_limit_notify = True,
                                retry_count = 5, 
                                retry_delay = 5 ).pages():
        following_getting += len(page)
        print 'user: %s --> collected %s following profiles of %s' % (user,following_getting,num_following)
        for profile in page:
          relation='following'
          if profile.id in dict_friends:
            relation='friend'
          if relation == 'friend' and not flag_friends:
            pass
          else:
            put_profile (api,user,profile,relation,f_log, f_out)
github nschaetti / pyTweetBot / pyTweetBot / twitter / TweetBotConnect.py View on Github external
def get_followers(self, n_pages=-1):
        """
        Get followers
        :return:
        """
        follower_list = list()
        page_count = 0
        # For each pages
        for page in tweepy.Cursor(self._api.followers).pages():
            # For each follower in the page
            for follower in page:
                follower_list.append(follower)
            # end for

            # Inc
            page_count += 1

            # Limit
            if n_pages != -1 and page_count >= n_pages:
                break
            # end if

            # Wait 60s
            time.sleep(60)
        # end for
github CruiseDevice / twweet-cli / twweet_cli.py View on Github external
def readTimeLine(api):
    for status in tweepy.Cursor(api.home_timeline).items(10):
        # process a single status
        # print(status.text)
        process_or_store(status._json)
github projeto7c0 / 7c0-core / twitter.py View on Github external
def list_tweets_list(topo):
    api = twitter_auth.autentica_list()

    tweets = []

    for status in tweepy.Cursor(api.list_timeline,tweet_mode='extended', owner_screen_name="projeto7c0", slug="politicos-br", since_id=topo, count=200).items():
        print(status)
        tweets.append(status)

    return tweets
github SMAPPNYU / smappPy / smappPy / user_collection / build_friends_followers.py View on Github external
def get_followers_ids(api, user_id):
    """
    Given a Tweepy/smappPy TweepyPool api, query twitter's rest API for followers of
    given user_id. Returns IDs only (much faster / more per request).
    Parameters:
        api     - fully authenticated Tweepy api or smappPy TweepyPool api
        user_id - twitter user id
    Returns tuple: return code, list of IDs or None (if API call fails)
    """
    cursor = Cursor(api.followers_ids, user_id=user_id)
    user_list, ret_code = call_with_error_handling(list, cursor.items())

    if ret_code != 0:
        logger.warning("User {0}: Followers request failed".format(user_id))
    
    # Return user list from API or None (call_with_error_handling returns None if
    # call fail)
    return ret_code, user_list
github Harmon758 / Harmonbot / Discord / cogs / twitter.py View on Github external
async def twitter_status(self, ctx, handle : str, replies : bool = False, retweets : bool = False):
		'''
		Get twitter status
		Excludes replies and retweets by default
		Limited to 3200 most recent Tweets
		'''
		tweet = None
		if handle.lower().strip('@') in self.blacklisted_handles:
			return await ctx.embed_reply(":no_entry: Error: Unauthorized")
		try:
			for status in tweepy.Cursor(self.bot.twitter_api.user_timeline, screen_name = handle, 
										exclude_replies = not replies, include_rts = retweets, 
										tweet_mode = "extended", count = 200).items():
				tweet = status
				break
		except tweepy.error.TweepError as e:
			if e.api_code == 34:
				return await ctx.embed_reply(f":no_entry: Error: @{handle} not found")
			else:
				return await ctx.embed_reply(f":no_entry: Error: {e}")
		if not tweet:
			return await ctx.embed_reply(":no_entry: Error: Status not found")
		text = self.process_tweet_text(tweet.full_text, tweet.entities)
		image_url = None
		if hasattr(tweet, "extended_entities") and tweet.extended_entities["media"][0]["type"] == "photo":
			image_url = tweet.extended_entities["media"][0]["media_url_https"]
			text = text.replace(tweet.extended_entities["media"][0]["url"], "")
github psychemedia / newt / newt.py View on Github external
i=0
  membersid=[]
  for id in members:
    membersid.append(members[id].id)
  M=len(members)
  Ms=str(M)
  for id in members:
    i=i+1
    friend=members[id]
    foafs={}
    report("- finding "+typ+" of whatever (friends? followers?) was passed in of "+friend.screen_name+' ('+str(i)+' of '+Ms+')')
    #danger hack AJH TH - try to minimise long waits for large friend counts
    if typ == 'friends' and int(friend.friends_count)>0 and int(friend.friends_count)0 and int(friend.followers_count)
github georgeglessner / TwitterWordOccurrences / tweet_analyzer.py View on Github external
output_file = args.file

    tweets = []  # list of tweets obtained from user timeline
    count = defaultdict(int)
    total_tweets_analyzed = 0
    total_results = 0

    # make connection
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth, wait_on_rate_limit=True)

    print('\nAnalyzing tweets. This could take a few seconds...')

    # get tweets from user's timeline
    for tweet in tweepy.Cursor(api.user_timeline, screen_name=user).items():
        tweets.append(tweet._json['text'].lower())

    # get rid of stop words
    # list of stop words https://gist.github.com/sebleier/554280
    stop_words = stopwords.words('english') + list(
        string.punctuation) + ['“', '”']

    # words to ignore in results
    BACKLIST_WORDS = [
        'https',
        '``',
        '...',
        'http',
        'rt',
    ]
github codeforfrankfurt / PolBotCheck / polbotcheck / twitter_api.py View on Github external
def save_tweets_with_retweets(screen_name):
    timestamp = time.strftime("%d.%m.%Y %H:%M:%S", time.localtime())
    print(timestamp)
    for tweet in limit_handled(tweepy.Cursor(TWITTER_API.user_timeline, id=screen_name, count=200).items()):
        retweets = get_retweets(tweet.id)
        db.saveRetweets(tweet, retweets)