使用Python Tweepy在Twitter API上提出非常具体的时间请求(至第二个)? [英] Making very specific time requests (to the second) on Twitter API, using Python Tweepy?

查看:101
本文介绍了使用Python Tweepy在Twitter API上提出非常具体的时间请求(至第二个)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Python Tweepy请求有关特定主题的推文(例如: cancer)。但是通常它的时间只能由特定的日期指定,例如。

I would like to request tweets on a specific topic (for example: "cancer"), using Python Tweepy. But usually its time can only be specified by a specific day, for example.

startSince = '2014-10-01'
endUntil = '2014-10-02'

for tweet in tweepy.Cursor(api.search, q="cancer", 
    since=startSince, until=endUntil).items(999999999):

是否可以指定时间,以便收集癌症推文在2014-10-01 00:00:00和2014-10-02 12:00:00之间?这是为我的学术研究而准备的:我能够收集上个月的癌症推文,但是由于癌症认识月份的到来,乳腺癌推文的数量突然激增,这破坏了我的脚本,我必须在不同的时间段收集它们,如果我很快无法找到,我将无法检索2014年10月1日的推文。

Is there a way to specify the time so I can collect "cancer" tweets between 2014-10-01 00:00:00 and 2014-10-02 12:00:00? This is for my academic research: I was able to collect cancer tweets for the last month, but the sudden burst of quantity of "breast cancer" tweets due to the cancer awareness month breaks my script and I have to collect them in different time segments, and I will not be able to retrieve the tweets for Oct 01, 2014 if I can't figure it out soon.

推荐答案

我找不到从/直到现在的特定时间。

There is no way that I've found to specific a time using since/until.

您可以使用 since_id & max_id

You can hack your way around this using since_id & max_id.

如果您可以在想要的时间找到一条推文,可以将搜索范围限制为之后 since_id 之前 max_id

If you can find a tweet made at around the times you want, you can restrict you search to those made after since_id and before max_id

import tweepy

consumer_key        = 'aaa'
consumer_secret     = 'bbb'
access_token        = 'ccc'
access_token_secret = 'ddd'

# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

results = api.search(q="cancer", since_id=518857118838181000, max_id=518857136202194000)

for result in results:
    print result.text

这篇关于使用Python Tweepy在Twitter API上提出非常具体的时间请求(至第二个)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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