据我所知,Twitter REST API有严格的请求限制(每15分钟几百次),并且流式API有时更适合检索实时数据.
我的问题是,流API的限制是什么?Twitter引用了他们文档的百分比,但没有具体数量.非常感谢任何见解.
我正在做的事情:
api twitter tweetstream twitter-streaming-api twitter-rest-api
我有一个python脚本,使用基本身份验证和使用tweetstream模块挂钩到Twitter Streaming API.
我每分钟收集10条推文.
我正在断断续续地断开连接,因此目前正在记录它们发生的频率.
我一直在达到我的速率限制并获得420个HTTP错误.
我知道,对于搜索API,您可以使用OAuth身份验证获得更高的配额.对于流媒体,我找不到任何关于基本和OAuth之间的速率限制差异的参考.无论如何,看起来我正在使用的python Tweetstream不支持使用流API.
我注意到Tweetstream的Ruby版本支持OAuth,但我正在做这个项目作为python的学习经验.
从阅读Twitter帮助,它谈到'退避战略'并提到:
如果收到HTTP 420响应,则必须停止几分钟的进一步连接尝试.
我不再收到错误,但一直试图在我的代码中制定更好的逻辑,以避免永久性地获得这些错误.
我目前的提议如下,在尝试重新连接之前现在等待200秒.
while True:
try:
with tweetstream.FilterStream(uname, passwd, locations=extent) as stream:
# do stuff
except tweetstream.ConnectionError as e:
print e.message + " time: " + datetime.now
time.sleep(200)
pass
except tweetstream.AuthenticationError as e:
now = datetime.datetime.now()
print e.message + " time: " + str(now)
pass
Run Code Online (Sandbox Code Playgroud)
我的问题是 - 这是一个很好的方式来绕过接收来自Twitter的420错误?那些更熟悉Twitter API的人,你能推荐一种方法吗?
我的Rails应用程序有一个关键的工作进程,这是Twitter提要事件上的事件机器循环(有人发推文,它会自动处理推文并根据内容运行不同的代码,也称为tweetstream gem).
我的问题是我不知道监控生产过程的正确/好方法,这样如果过程失败或工作不正常,我希望以某种方式得到通知,以便我可以尝试解决它很快.我有NewRelic gem来监视我的Web服务器,但是还不确定它是否/如何应用于工作线程.
我在找什么:
我正在寻找的是正常记录器工作流程的一部分,(使用不同的日志级别?)如果是这样,确认这对我来说也很有帮助.任何建议表示赞赏,谢谢!
编辑:说NewEgg而不是NewRelic ......哎呀
monitoring ruby-on-rails heroku production-environment tweetstream
我正在尝试使用Tweepy从特定位置获取推文,但是当我运行代码时出现此错误
raise TweepError("Wrong number of locations points, "
tweepy.error.TweepError: Wrong number of locations points, it has to be a multiple of 4
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我尝试使用NY的位置坐标从纽约市获取推文.我怎样才能从纽约单独得到推文?我的猜测是在x,y和y,z之间使用一系列坐标.我该怎么做?
这是我的代码:
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
try:
print(data)
saveFile = open('newtweets.csv', 'a')
saveFile.write(data)
saveFile.write('/n').encode("utf-8")
saveFile.close()
return True
except BaseException:
print ('failed ondata')
time.sleep(5)
def on_error(self, status):
print(status.encode("utf-8"))
if __name__ == '__main__':
l = …
Run Code Online (Sandbox Code Playgroud) 我有N个跟踪的不同关键字(为简单起见,让N = 3).所以在GET状态/过滤器中,我将在"track"参数中给出3个关键字.
现在我将收到的推文可以来自我提到的3个关键词中的任何一个.问题是我想解决哪个推文对应哪个关键字.即推文和关键字之间的映射(在"track"参数中提到).
显然,没有对收到的推文进行任何处理就没有办法做到这一点.
所以我想知道进行这种处理的最佳方法是什么?在推文文本中搜索关键字?不区分大小写的情况怎么样?当同一个关键词中存在多个单词时,例如:"Katrina Kaif"?
我目前正在尝试制定一些正则表达式......
我认为最好的方法是使用与最初使用的状态/过滤器API相同的逻辑(正则表达式等).如何知道Twitter API状态/过滤器本身使用什么逻辑来匹配推文到关键字?
建议吗?救命?
PS:我使用的是Python,Tweepy,Regex,MongoDb/Apache S4(用于分布式计算)
我正在构建一个使用TweetStream的Sinatra应用程序(使用EventMachine侦听推文).我也希望该应用程序像普通的Sinatra应用程序一样提供页面,但似乎Sinatra在"倾听"推文时无法"收听"页面请求.
这是我可以通过使用不同的服务器或以不同的方式构建我的应用程序来解决的问题吗?我尝试过使用WebBrick和Thin.
这基本上就是我在做的事情:
class App < Sinatra::Base
# listening for tweets
@client = TweetStream::Client.new
@client.track(terms) do |status|
# do some stuff when I detect terms
end
get '/' do
"Here's some page content!"
end
end
Run Code Online (Sandbox Code Playgroud) 使用TweetStream运行以下示例时,我得到提到的错误.
tweets.rb
require 'tweetstream'
TweetStream.configure do |config|
config.consumer_key = '<CONSUMER KEY>'
config.consumer_secret = '<CONSUMER SECRET>'
config.oauth_token = '<OAUTH TOKEN>'
config.oauth_token_secret = '<OAUTH TOKEN SECRET'
config.auth_method = :oauth
end
TweetStream::Client.new.track('ruby') do |status|
puts "#{status.text}"
end
Run Code Online (Sandbox Code Playgroud)
错误
$ ruby tweets.rb
/home/amit/.rvm/gems/ruby-1.9.3-p194/gems/tweetstream-2.3.0/lib/tweetstream/client.rb:96:in `track': undefined method `extract_options!' for ["ruby"]:Array (NoMethodError)
from tweets.rb:11:in `<main>'
https://github.com/intridea/tweetstream
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我试图将每个打开的推文都放在一个标签中,但我的代码不会超过 299 条推文。
我还尝试从特定时间线获取推文,例如仅在 2015 年 5 月和 2016 年 7 月的推文。有没有办法在主进程中执行此操作,还是应该为其编写一些代码?
这是我的代码:
# if this is the first time, creates a new array which
# will store max id of the tweets for each keyword
if not os.path.isfile("max_ids.npy"):
max_ids = np.empty(len(keywords))
# every value is initialized as -1 in order to start from the beginning the first time program run
max_ids.fill(-1)
else:
max_ids = np.load("max_ids.npy") # loads the previous max ids
# if there is any new keywords added, …
Run Code Online (Sandbox Code Playgroud) 不要安装这个宝石,我得到这个回应.
greg@greg-VirtualBox:~$ gem install tweetstream
Building native extensions. This could take a while...
ERROR: Error installing tweetstream:
ERROR: Failed to build gem native extension.
/home/greg/.rvm/rubies/ruby-1.9.3-p362/bin/ruby extconf.rb
checking for main() in -lssl... yes
checking for main() in -lcrypto... yes
checking for openssl/ssl.h... yes
checking for openssl/err.h... yes
checking for rb_trap_immediate in ruby.h,rubysig.h... no
checking for rb_thread_blocking_region()... yes
checking for inotify_init() in sys/inotify.h... yes
checking for writev() in sys/uio.h... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enable_interrupt()... yes
checking for rb_time_new()... yes …
Run Code Online (Sandbox Code Playgroud) 有没有人知道一个Ruby gem或插件,它提供了一个简单的Twitter Steams API接口?
这可能是一个菜鸟错误,但我在学习python的早期阶段.
不太清楚我做错了什么,或者如何纠正这个问题.
这是一个简短的截屏视频,如果它再流光了.
编辑 - 回应评论.
c:\tweetstream-1.1.1>python setup.cfg install
File "setup.cfg", line 2
tag_build =
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud) tweetstream ×11
python ×5
twitter ×5
ruby ×4
tweepy ×3
api ×1
eventmachine ×1
gem ×1
geolocation ×1
heroku ×1
linux ×1
monitoring ×1
python-2.7 ×1
sinatra ×1