#python #api #arduino #tweepy
Вопрос:
Я хочу сделать настраиваемое уведомление о твите с помощью arduino и python. Для этого будут использоваться библиотеки python tweepy и serial, я настроил класс StreamListener, но по какой-то причине arduino не гудит. Я не могу найти ничего, относящегося к Интернету.
Вот что у меня есть:
try:
serial_port = "COM5"
baud_rate = 115200
arduino_serial_connection = serial.Serial(serial_port, baud_rate)
print("Connection established on %s" % serial_port)
arduino_serial_connection.write(99)
except IndexError:
print("No arduino device port specified, Exit")
sys.exit()
except BaseException as b:
print (b)
sys.exit()
user_name = ['UniProjectBot']
# Class by tweepy to access the Twitter Streaming API
class StreamListener(tweepy.StreamListener):
def play_sound(self):
# Plays a beep on the Arduino
arduino_serial_connection.write(1)
sleep(4)
arduino_serial_connection.write(99)
def on_connect(self):
# Called to connect to the API
print("You are now connected to the streaming API")
def on_error(self, status_code):
# If error occurs, display the eroor / status code
print("An Error has occured: " repr(status_code))
return False
def on_data(self, data):
try:
datajson = json.loads(data)
text = datajson['text']
screen_name = datajson['user']['screen_name']
tweet_id = datajson['id']
print("Tweet found: " str(screen_name) str(text))
self.play_sound()
except Exception as e:
print(e)
auth = tweepy.OAuthHandler(API_Keys.consumer_key, API_Keys.consumer_secret)
auth.set_access_token(API_Keys.key, API_Keys.secret)
listener = StreamListener(api = tweepy.API(wait_on_rate_limit=True))
streamer = tweepy.Stream(auth=auth, listener=listener)
print("Watching: " str(user_name))
streamer.filter(track=user_name)