0
即時通訊嘗試運行一個簡單的Twitter搜索tweepy的Python腳本。我希望能夠通過Supercollider的OSC消息啓動/關閉搜索功能。最終目標是讓OSC觸發器停止並重新啓動搜索功能。重置Tweepy跟蹤與OSC觸發
目前,腳本似乎無法同時收聽twitter流和OSC消息。我一直試圖結合tweepy基本streamlistener代碼和pyOSC basic_receive代碼。
這就是我想出了:
import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import threading
import OSC
import time, threading
auth/api
#from basic_receive.py
receive_address = '127.0.0.1', 9000
s = OSC.OSCServer(receive_address)
def printing_handler(addr,tags,stuff,source):
global word
word = stuff[0]
print word
return
s.addMsgHandler("/print", printing_handler)
st = threading.Thread(target = s.serve_forever)
st.start()
try:
while 1:
time.sleep(1)
except KeyboardInterrupt :
print "\nClosing OSCServer."
s.close()
print "Waiting for Server-thread to finish"
st.join() ##!!!
print "Done"
#from Tweepy
class StdOutListener(StreamListener):
global word
def __init__(self, api=None):
super(StdOutListener, self).__init__()
self.num_tweets = 0
def on_status(self, status):
text = status.text
print text
self.num_tweets = self.num_tweets + 1
if self.num_tweets > 1000:
return False
elif word == 'haha':
return False
else:
return True
def on_error(self, status):
print(status)
return True
def track():
stream = Stream(auth, listener)
stream.filter(track = ['food', 'love'])
return
if __name__ == '__main__':
listener = StdOutListener()
track()
printing_handler()
謝謝jm_____它絕對需要更多的工作!會讓你更新:) –