def ping(IP_DEVICE, connected): print("ping ", IP_DEVICE) proc = subprocess.Popen(["ping", IP_DEVICE], stdout=subprocess.PIPE) found = False while True: line = proc.stdout.readline() if not line: break line = line.decode("utf-8") # condizione bruttissima ma per ora è l'unica idea che ho avuto if line.find("Tempo") != -1: found = True if not connected: connected = True status(connected) play() break if not found: connected = False status(connected) pause() return connected
def get_response(intents_list, intents_json): tag = intents_list[0]["intent"] if intents_list[0]['probability'] < 0.65: return "I don't understand. Please try again." list_of_intents = intents_json['intents'] for i in list_of_intents: if i["tag"] == tag: resoult = random.choice(i["responses"]) if tag == "time": resoult = resoult.replace("xxx", datetime.now().strftime("%H:%M")) if tag == "date": resoult = resoult.replace("xxx", date.today().strftime("%d/%m/%Y")) if tag == "music": spotify.play() if tag == "music-stop": spotify.stop() break return resoult
def nextHandler(): spotify.pause() spotify.next() json = spotify.currentTrack() spotify.play() return json
def playHandler(): spotify.play() return spotify.currentTrack()
def previousHandler(): spotify.pause() spotify.previous() json = spotify.currentTrack() spotify.play() return json
from time import sleep import sys from mfrc522 import SimpleMFRC522 import spotify from album_mapping import NFC_TO_ALBUM import RPi.GPIO as GPIO reader = SimpleMFRC522() last_uri = "" try: while True: print("Hold a tag near the reader") id, text = reader.read() print("ID: %s\nText: %s" % (id, text)) last_3_chars = id % 1000 spotify_uri = NFC_TO_ALBUM.get(last_3_chars) if not spotify_uri: print("NFC not in dict {}".format(last_3_chars)) elif spotify_uri != last_uri: # Don't play it twice last_uri = spotify_uri print("Playing {}".format(spotify_uri)) spotify.play(spotify_uri) sleep(5) except KeyboardInterrupt: GPIO.cleanup() raise