我有 twython 流媒体的代码,它正在工作。
def read_cred(file): in_handle = open(file,'r')
cred = {}
for ln in in_handle:
data = ln.strip('\r\n').split('=')
if len(data) > 1:
key = data[0].strip(' ').lower()
value = data[1].strip(' ')
cred[key] = value
else:
print "error in parsing credentials file"
return cred
cred = read_cred(sys.argv[1])
类 MyStreamer(TwythonStreamer): def on_success(self, data): act(data)
def on_error(self, status_code, data):
print status_code, data
流 = MyStreamer(cred['consumer_key'], cred['consumer_secret'], cred['access_token_key'], cred['access_token_secret'])
关键字 = sys.argv[2]
stream.statuses.filter(track=keywords)
但是,我想在 django 框架中创建一个包含“开始”和“停止”按钮的 UI。当我单击“停止”按钮时,我应该怎么做才能停止 twython 流媒体?可以给我一些简单的例子吗?