用于低 API 调用的 Tweepy Cursor 与迭代 [英] Tweepy Cursor vs Iterative for low API calls

查看:27
本文介绍了用于低 API 调用的 Tweepy Cursor 与迭代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的 Tweepy 应用程序以供娱乐,但实际上仅限于多少我有 API 调用(150 到 350 之间的任何地方).因此,为了解决这个问题,我正在寻找减少通话的方法.Tweepy 有一个内置的游标系统.例如:

I am writing a simple Tweepy application for fun, but am really limited to how many API calls I have (anywhere between 150 and 350). So to account for this I am looking for ways to cut calls. Tweepy has a cursor system built in. Eg:

# Iterate through all of the authenticated user's friends
for follower in tweepy.Cursor(api.followers).items():
    follower.follow()

对于那些熟悉这个库的人.上面的例子比简单的...效率更高还是更低?

For those who are familiar with this library. Would the above example be more or less efficient than simply...

for follower in api.followers_ids():
    api.follow(follower)

除了使用 Cursor 方法比迭代方法简单之外还有其他优点吗?

Are there any other advantages apart from simplicity to use the Cursor method over an iterative method?

提前致谢.

推荐答案

如果我在使用 tweepy 时没记错的话,Cursor 对象会自动在 上分页n 很多元素...例如,如果有 10,000 个结果,并且 Twitter 一次返回(比如说)200,那么使用 Cursor 将返回所有 10,000,但必须使调用以继续检索下一个.

If I remember correctly from my use of tweepy, a Cursor object automatically paginates over n many elements... For instance, if there are 10,000 results, and Twitter returns (say) 200 at a time, then using the Cursor will return all 10,000 but will have to make a call to keep retrieving the next ones.

OTOH,api.followers_ids() 只返回结果的第一个页面",所以可能是前 100 个或其他.

OTOH, api.followers_ids() only returns the first "page" of results, so maybe the first 100 or whatever.

这篇关于用于低 API 调用的 Tweepy Cursor 与迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆