im trying to run a python script that does a simple twitter search with tweepy. i want to be able to trigger the search function on/off through OSC messages from Supercollider. The ultimate goal is to have an OSC trigger stop and restart the search function.
Currently, it seems like the script is not able to listen to both the twitter stream and the OSC messages. i've been trying to combine the tweepy basic streamlistener code and the pyOSC basic_receive codes.
Here's what i came up with :
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()