我有一个小脚本,它使用 tweetstream 获取推文的数量并将其写入文件,但我看到有 50/s 的限制,可能是因为文件 IO,我想尝试将值存储在变量中然后,每 10 分钟用变量的值写入文件,我该怎么做?
#!/usr/bin/python
import tweetstream
import sys
print sys.argv
twitterUsername = "username"
twitterPassword = "password"
twitterWordFilter = sys.argv[1]
try:
with tweetstream.FilterStream(twitterUsername, twitterPassword,track=twitterWordFilter) as stream:
for tweet in stream:
file = open('/monitor/'+str(sys.argv[2])+'.txt','w+')
file.write(str(stream.count))
file.close
#print tweet #Use for raw output
except tweetstream.ConnectionError, e:
print "Disconnected from twitter. Reason:", e.reason