def speak_weather(): weather = get_weather() description = weather["weather"][0]["description"] temp = weather["main"]["temp"] send_notification(f"Temp: {temp}°C, Description: {description}") speak( f"today we have a {description} and we are at {temp} degrees celsius")
def knightfall_protocol(): speak('knightfall protocol requires a voice code') if audio_confirmation(): speak("activating knightfall protocol") speak('good night') return os.system('systemctl poweroff') speak('Voice code denied, aborting activation of knightfall protocol')
def bootstrap_protocol(): speak("hi, activating bootstrap protocol") speak("opening your sites") handle_open("open notion") handle_open("open habitica") speak("consulting your daily informations") handle_check_plans("today") speak_weather() handle_news()
def handler(text): if not text: return intent = intent_predictor.predict(text) print(intent) try: if not intent: return speak(text) if intent == "check_calendar": return date.handle_check_plans(text) if intent == "search": return speak("search") if intent == "news": news.handle_news() if intent == "weather": weather.speak_weather() if intent == "open": applications.handle_open(text) if intent == "protocol": protocol.handle_protocol(text) except Exception as e: print(e) speak("Sorry, I can't understand you")
def _speakEvents(events): if not events: return voice.speak('No upcoming events found') if (len(events) == 1): voice.speak(f'You have {len(events)} event') else: voice.speak(f'You have {len(events)} events') for event in events: event_datetime = dateutil.parser.parse(event['start'].get( 'dateTime', event['start'].get('date'))) start_time = event_datetime.hour time_period = 'am' if start_time > 12: start_time -= 12 time_period = 'pm' event_desc = event['summary'] voice.speak(f'{event_desc} at {start_time} {time_period}')
def handle_search(trigger, text): topic = re.search(f'.*{trigger} (a |the )?(.*)', text).group(2) voice.speak(f'Okay') search(topic)
def handle_news(): voice.speak("playing the brazilian news now") headlines = get_top_headlines() for headline in headlines: send_notification(headline['title']) voice.speak(headline['title'], lang="pt-br")