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 compareDate(self, input, target): service = DateService() result = service.extractDate(input) self.assertEqual(result.month, target.month) self.assertEqual(result.day, target.day)
def compareTime(self, input, target): service = DateService() result = service.extractDate(input) self.assertEqual(result.hour, target.hour) self.assertEqual(result.minute, target.minute)
def compareDate(self, input, target): service = DateService() result = service.extractDate(input) self.assertEqual(target, result)
#https://pypi.org/project/semantic/ ##create virtual env for package installation #virtualenv semanticenv ##deactivate the existing virtual env ##activate the virtual env #semanticenv\Scripts\activate #pip install semantic from semantic.dates import DateService from semantic.dates import DateService service = DateService() date = service.extractDate("On March 3 at 12:15pm...") #--------------------------------------------------- #this fails # from semantic.solver import ConversionService # service = ConversionService() # print (service.convert("Seven and a half kilograms to pounds")) # print (service.convert("Seven and a half pounds per square foot to kilograms per meter squared")) #-------------- from semantic.numbers import NumberService service = NumberService() print(service.parse("Two hundred and six")) # 206 print(service.parse("Five point one five")) # 5.15
def compareDate(self, inp, target): service = DateService() result = service.extractDate(inp) self.assertEqual(result.month, target.month) self.assertEqual(result.day, target.day)
def compareTime(self, inp, target): service = DateService() result = service.extractDate(inp) self.assertEqual(result.hour, target.hour) self.assertEqual(result.minute, target.minute)