Twitter の公開タイムラインをストリーミングする簡単なアプリを作成しています。1 時間後にストリーミングを自動的に停止したいのですが、その方法がわかりません。datetime と timeit のドキュメントを読みましたが、理解できません。これが私のコードで、私が望むタイムラインを完全にストリーミングしていますが、無期限です。
from twython import TwythonStreamer
import json
import os
import datetime
from datetime import *
APP_KEY = 'XX'
APP_SECRET = 'XX'
OAUTH_TOKEN = 'XX'
OAUTH_TOKEN_SECRET = 'XX'
class MyStreamer(TwythonStreamer):
def on_success(self, data):
print data['text']
with open('scratch1.json', 'ab') as outfile:
json.dump(data, outfile, indent = 4)
with open('scratch2.json', 'ab') as xoutfile:
json.dump(data, xoutfile, indent = 4)
return
def on_error(self, status_code, data):
print status_code
return True # Don't kill the stream
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True # Don't kill the stream
stream = MyStreamer(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(follow = [95995660, 8820362])
誰でも私を助けることができますか?