def handle(text, mic, profile): print "I'm Time.py" tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) service = DateService() response = service.convertTime(now) mic.say("It is %s right now." % response)
def handle(text, mic, profile): """ Responds to user-input, typically speech text, with a summary of the relevant weather for the requested date (typically, weather information will not be available for days beyond tomorrow). Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ if not profile['location']: mic.say( "I'm sorry, I can't seem to access that information. Please make sure that you've set your location on the dashboard.") return tz = getTimezone(profile) service = DateService(tz=tz) date = service.parseDay(text) if not date: date = datetime.datetime.now(tz=tz) weekday = service.__daysOfWeek__[date.weekday()] if date.weekday() == datetime.datetime.now(tz=tz).weekday(): date_keyword = "Today" elif date.weekday() == ( datetime.datetime.now(tz=tz).weekday() + 1) % 7: date_keyword = "Tomorrow" else: date_keyword = "On " + weekday forecast = getForecast(profile) output = None for entry in forecast: try: date_desc = entry['title'].split()[0].strip().lower() weather_desc = entry['summary'].split('-')[1] if weekday == date_desc: output = date_keyword + \ ", the weather will be" + weather_desc + "." break except: continue if output: output = replaceAcronyms(output) mic.say(output) else: mic.say( "I'm sorry. I can't see that far ahead.")
def handle(text, mic, profile, logger, modules): """ Responds to user-input, typically speech text, by listing the user's Facebook friends with birthdays today. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ oauth_access_token = profile['keys']["FB_TOKEN"] graph = GraphAPI(oauth_access_token) try: results = graph.request("me/friends", args={'fields': 'id,name,birthday'}) except GraphAPIError: logger.error("error getting response form facebook api, for key: %s" % oauth_access_token, exc_info=True) mic.say( "Nie mam uprawnienia do twojego konta na Fejsbuku. Sprawdź ustawienia." ) return except: logger.error("error getting response form facebook api, for key: %s" % oauth_access_token, exc_info=True) mic.say("Wybacz, ale ta usługa jest chwilowo niedostępna.") return needle = datetime.datetime.now(tz=getTimezone(profile)).strftime("%m/%d") logger.debug("friends list %s" % results) people = [] for person in results['data']: try: logger.debug("name %s birthday %s" % (person['name'], person['birthday'])) if needle in person['birthday']: people.append(person['name']) except: logger.error("error parsing contact list", exc_info=True) continue if len(people) > 0: if len(people) == 1: output = people[0] + " ma dzisiaj urodziny." else: output = "Oto znajomi, którzy dzisiaj obchodzą urodziny " + \ ", ".join(people[:-1]) + " oraz " + people[-1] + "." else: output = "Nikt z twoich znajomych nie obchodzi dzisiaj urodzin." mic.say(output)
def handle(text, sender, receiver, profile): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) service = DateService() response = service.convertTime(now) sender.say("It is %s right now." % response)
def handle(text, mic, profile, house): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) service = DateService() response = service.convertTime(now) mic.say("It is %s right now." % response)
def handle(self, text, teller, mic, profile): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (input) profile -- contains information related to the user (e.g., phone number) """ tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) service = DateService() response = service.convertTime(now) teller.say("Il est %s." % response)
def handle(text, mic, profile): """ Responds to user-input, typically speech text, with a summary of the relevant weather for the requested date (typically, weather information will not be available for days beyond tomorrow). Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ try: weather_client = yweather.Client() weather = weather_client.fetch_weather(profile["location"]["id"], metric=True) tz = getTimezone(profile) service = DateService(tz=tz) date = service.extractDate(text) if not date: date = datetime.datetime.now(tz=tz) weekday = service.__daysOfWeek__[date.weekday()] if date.weekday() == datetime.datetime.now(tz=tz).weekday(): mic.say( ("Today, %s at %s degrees with wind speed" + " of %.1f metres per second") % (code2desc(weather["condition"]), weather["condition"]["temp"], float(weather["wind"]["speed"]) / 3.6) ) return elif date.weekday() == (datetime.datetime.now(tz=tz).weekday() + 1) % 7: date_keyword = "Tomorrow" else: date_keyword = "On " + weekday weekdays = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"] for fore in weather["forecast"]: if weekdays[date.weekday()] == fore["day"]: mic.say( ("%s, %s with temperatures raging" + " from %s to %s degrees") % (date_keyword, code2desc(fore), fore["low"], fore["high"]) ) break else: mic.say("I'm sorry. I can't see that far ahead.") except: mic.say("I'm sorry. I can't see that far ahead.")
def handle(text, mic, profile, logger, modules): """ Responds to user-input, typically speech text, by listing the user's Facebook friends with birthdays today. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ oauth_access_token = profile["keys"]["FB_TOKEN"] graph = GraphAPI(oauth_access_token) try: results = graph.request("me/friends", args={"fields": "id,name,birthday"}) except GraphAPIError: logger.error("error getting response form facebook api, for key: %s" % oauth_access_token, exc_info=True) mic.say("Nie mam uprawnienia do twojego konta na Fejsbuku. Sprawdź ustawienia.") return except: logger.error("error getting response form facebook api, for key: %s" % oauth_access_token, exc_info=True) mic.say("Wybacz, ale ta usługa jest chwilowo niedostępna.") return needle = datetime.datetime.now(tz=getTimezone(profile)).strftime("%m/%d") logger.debug("friends list %s" % results) people = [] for person in results["data"]: try: logger.debug("name %s birthday %s" % (person["name"], person["birthday"])) if needle in person["birthday"]: people.append(person["name"]) except: logger.error("error parsing contact list", exc_info=True) continue if len(people) > 0: if len(people) == 1: output = people[0] + " ma dzisiaj urodziny." else: output = ( "Oto znajomi, którzy dzisiaj obchodzą urodziny " + ", ".join(people[:-1]) + " oraz " + people[-1] + "." ) else: output = "Nikt z twoich znajomych nie obchodzi dzisiaj urodzin." mic.say(output)
def handle(text, mic, profile): """ Responds to user-input, typically speech text, by listing the user's Facebook friends with birthdays today. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ oauth_access_token = profile['keys']["FB_TOKEN"] graph = facebook.GraphAPI(oauth_access_token) try: results = graph.request("me/friends", args={'fields': 'id,name,birthday'}) except facebook.GraphAPIError: mic.say("I have not been authorized to query your Facebook. If you " + "would like to check birthdays in the future, please visit " + "the Jasper dashboard.") return except: mic.say( "I apologize, there's a problem with that service at the moment.") return needle = datetime.datetime.now(tz=getTimezone(profile)).strftime("%m/%d") people = [] for person in results['data']: try: if needle in person['birthday']: people.append(person['name']) except: continue if len(people) > 0: if len(people) == 1: output = people[0] + " has a birthday today." else: output = "Your friends with birthdays today are " + \ ", ".join(people[:-1]) + " and " + people[-1] + "." else: output = "None of your friends have birthdays today." mic.say(output)
def handle(text, mic, profile): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) service = DateService() response = service.convertTime(now) #cluetext = " Listen very carefully to the next clue: The letter P is the start of its name. The letter R is the end. It runs at night but never goes anywhere. Look inside " mic.say("It is %s right now." % response)
def alarmclock(profile, mic, *args): print 'set up !' while (len(hours) != 0): tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) lock.acquire(True) for i, (h, m) in enumerate(hours): hour_now = now.hour min_now = now.minute #mic.say("it is now %s %s and alarm is %s %s" % (hour_now, min_now, h, m)) if (hour_now == h and min_now == m): print 'ringing !' #TODO integrate it with xbmc cmd = 'vlc ' + profile['alarm_file'] print cmd subprocess.Popen(cmd, shell=True) #suppress the hour if ringed del hours[i] lock.release() print 'exit, no more alarm to ring'
def alarmclock(profile, mic,*args): print 'set up !' while(len(hours)!=0): tz = getTimezone(profile) now = datetime.datetime.now(tz=tz) lock.acquire(True) for i, (h, m) in enumerate (hours): hour_now = now.hour min_now = now.minute #mic.say("it is now %s %s and alarm is %s %s" % (hour_now, min_now, h, m)) if(hour_now==h and min_now==m): print 'ringing !' #TODO integrate it with xbmc cmd='vlc '+profile['alarm_file'] print cmd subprocess.Popen(cmd, shell=True) #suppress the hour if ringed del hours[i] lock.release() print 'exit, no more alarm to ring'
def handle(text, mic, profile): """ Responds to user-input, typically speech text, with a summary of the relevant weather for the requested date (typically, weather information will not be available for days beyond tomorrow). Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ if not profile['location']: mic.say( "I'm sorry, I can't seem to access that information. Please make" + "sure that you've set your location on the dashboard.") return tz = getTimezone(profile) service = DateService(tz=tz) date = service.extractDay(text) if not date: date = datetime.datetime.now(tz=tz) weekday = service.__daysOfWeek__[date.weekday()] if date.weekday() == datetime.datetime.now(tz=tz).weekday(): date_keyword = "Today" elif date.weekday() == (datetime.datetime.now(tz=tz).weekday() + 1) % 7: date_keyword = "Tomorrow" else: date_keyword = "On " + weekday forecast = getForecast(profile) output = None for entry in forecast: try: date_desc = entry['title'].split()[0].strip().lower() if date_desc == 'forecast': # For global forecasts date_desc = entry['title'].split()[2].strip().lower() weather_desc = entry['summary'] elif date_desc == 'current': # For first item of global forecasts continue else: # US forecasts weather_desc = entry['summary'].split('-')[1] if weekday == date_desc: output = date_keyword + \ ", the weather will be " + weather_desc + "." break except: continue if output: output = replaceAcronyms(output) mic.say(output) else: mic.say("I'm sorry. I can't see that far ahead.")
def handle(text, mic, profile, logger, modules): """ Responds to user-input, typically speech text, with a summary of the relevant weather for the requested date (typically, weather information will not be available for days beyond tomorrow). Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) """ if not profile['location']: mic.say( "Wybacz, ale nie mogę podać prognozy pogody. Wprowadź proszę w ustawieniach miasto.") return mic.say("Pobieram prognozę pogody...") #str_formater.checkFormat(text, logger) text = str_formater.unicodeToUTF8(text, logger) tz = getTimezone(profile) service = DateService(tz=tz) loc = arrow.locales.get_locale('pl') #loc.day_name(1).lower() #date = service.extractDay(text) #if not date: dow = parseDayOfWeek(text.lower(), logger) if dow: now_dow = arrow.utcnow().weekday() if dow > now_dow: date = arrow.utcnow().replace(days=dow - now_dow) else: date = arrow.utcnow().replace(days=dow - now_dow + 7) if 'dzisiaj' in text.lower(): date = arrow.utcnow() elif 'jutro' in text.lower(): date = arrow.utcnow().replace(days=+1) elif 'pojutrze' in text.lower(): date = arrow.utcnow().replace(days=+2) else: date = arrow.utcnow() weekday = loc.day_name(date.weekday()+1).lower() weekday = str_formater.unicodeToUTF8(weekday, logger).replace('Ś','ś') if date.weekday() == arrow.utcnow().weekday(): date_keyword = "dzisiaj" elif date.weekday() == arrow.utcnow().replace(days=+1).weekday(): date_keyword = "jutro" else: date_keyword = weekday #logger.debug("date_keyword %s weekday %s" % (date_keyword, weekday)) forecast = getForecast(profile) output = "" #weekday = 'niedziela' #for entry in forecast: # print entry['title'] for entry in forecast: try: entry = str_formater.unicodeToUTF8(entry, logger) #str_formater.checkFormat(entry['title'].split()[0].strip().lower(), logger) date_desc = entry['title'].split()[0].strip().lower().replace('Ś','ś') #logger.debug('date_desc %s' % date_desc) if date_desc == 'prognoza': #For global forecasts date_desc = entry['title'].split()[2].strip().lower().replace('Ś','ś') #logger.debug('date_desc %s' % date_desc) weather_desc = entry['summary_detail']['value'] elif date_desc == 'obecne': #For first item of global forecasts output += "Obecne warunki pogodowe:|" + \ parseCurrentConditions(entry['summary_detail']['value']) + "| " continue else: weather_desc = entry['summary_detail']['value'].split('|')[1] #US forecasts if weekday == date_desc: output += "Prognoza pogody na " + \ date_keyword + ',| ' + weather_desc break except: logger.error("error parsing forecast", exc_info=True) if output: output = replaceAcronyms(output) mic.say(output) else: mic.say( "Wybacz, ale brak prognozy")