def test_timeChatbot(self): # test getTimezone question = 'what is the time in Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] [t1] = tc.getTimezone(entities) t2 = tc.getTimezone({}, 'Toronto') self.assertEqual(t1, t2) #print(t1, t2) # test getLocalTime [lt1] = tc.getLocalTime(entities) question = 'the local time of Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] lt2 = tc.getLocalTime(entities, 'Toronto') # their seconds may be a little different, because of time lag # but, generally speaking, their dates, hours and minutes should be the same lt1 = str(lt1)[:16] lt2 = str(lt2)[:16] self.assertEqual(lt1, lt2) # test getTimeDifference question = 'the time difference between London and Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] td1 = tc.getTimeDifference(entities) question = 'the time difference between Toronto and London' jsonData = wa.sendRequest(question) entities = jsonData['entities'] td2 = tc.getTimeDifference(entities) td1 = str(td1)[:16] td2 = str(td2)[:16] #print(td1, td2) self.assertEqual(td1, td2)
def test_geoInfo(self): # test get_temperature question = 'temperature in London' jsonData = wa.sendRequest(question) entities = jsonData['entities'] t1 = gi.get_temperature(entities) question = 'London temperature' jsonData = wa.sendRequest(question) entities = jsonData['entities'] t2 = gi.get_temperature(entities) self.assertEqual(t1, t2) #print(t1, t2) # test get_weather question = 'how about the weather in Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] w1 = gi.get_weather(entities) question = 'what is the weather of Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] w2 = gi.get_weather(entities) self.assertEqual(w1, w2) #print(w1, w2) # test get_point_of_interest question = 'what is the point of interest in Washington' jsonData = wa.sendRequest(question) entities = jsonData['entities'] poi1 = gi.get_point_of_interest(entities, limit=6) self.assertEqual(6, len(poi1))
def getResponse(question): question = scpt.check_spelling_update(question) question = sr.replaceSynonyms(question) jsonData = wa.sendRequest(question) response = "" intents = jsonData['intents'] entities = jsonData['entities'] traits = jsonData['traits'] for trait in traits: if trait == 'wit$greetings': response += "Hello! I can help with things related to geographic data.\nTry asking me how far two places are from each other, or ask me about the weather somewhere.\nIf you want to know more about what I can do, try asking for help.\n" if trait == 'help': response += "I have a few things I can help you with.\nI can get the temperature at multiple locations, the weather forecast, and points of interest nearby.\nI can also tell you what the local time is for any location, and help calculate time differences between locations.\nLastly, I can measure distances between two locations in kilometers.\n" if trait == 'wit$bye': response += "Goodbye!\n" if len(intents) == 0 and len(traits) == 0: response += oos.getResponse() else: # for each intent, call their appropriate function, pass the data to the formatter, and append the string to the response for intent in intents: intentName = intent['name'] response += witIntentResponseFormats[intentName]( witIntents[intentName](entities), entities) return response
def test_location(self): # test getLocation method L1 = lc.getLocation('here') L2 = lc.getLocation('me') L3 = lc.getLocation() self.assertEqual(L1, L2) self.assertEqual(L1, L3) L4 = lc.getLocation('New York') new_york = (40.7127281, -74.0060152) self.assertEqual(new_york, L4) toronto = (43.6534817, -79.3839347) L5 = lc.getLocation('Toronto') self.assertEqual(toronto, L5) # test distanceByLatLong question = 'distance from London to Toronto' jsonData = wa.sendRequest(question) entities = jsonData['entities'] d1 = lc.distanceByLatLong(entities) question = 'how far it is from Toronto to London' jsonData = wa.sendRequest(question) entities = jsonData['entities'] d2 = lc.distanceByLatLong(entities) self.assertEqual(d1, d2)
def getResponse(question): question = scpt.check_spelling_update(question) question = sr.replaceSynonyms(question) jsonData = wa.sendRequest(question) response = "" intents = jsonData['intents'] entities = jsonData['entities'] traits = jsonData['traits'] intext = jsonData["text"] mapReq = GoogleReq() if intext.startswith("translate"): trasContent = intext.replace("translate", "") return mapReq.do_translate(trasContent) if intext.startswith("direct"): addressArr = intext.replace("direct ", "").split(" to ") addressStart = addressArr[0].replace("from ", "").replace(" ", "") addressEnd = addressArr[1].replace(" ", "") print(addressStart) print(addressEnd) return mapReq.get_direct_info(addressStart, addressEnd) for trait in traits: if trait == 'wit$greetings': response += "Hello! I can help with things related to geographic data.\nTry asking me how far two places are from each other, or ask me about the weather somewhere.\nIf you want to know more about what I can do, try asking for help.\n" if trait == 'help': response += "I have a few things I can help you with.\nI can get the temperature at multiple locations, the weather forecast, and points of interest nearby.\nI can also tell you what the local time is for any location, and help calculate time differences between locations.\nLastly, I can measure distances between two locations in kilometers.\n" if trait == 'wit$bye': response += "Goodbye!\n" print(jsonData) if len(intents) == 0 and len(traits) == 0: response += oos.getResponse() else: # for each intent, call their appropriate function, pass the data to the formatter, and append the string to the response for intent in intents: intentName = intent['name'] response += witIntentResponseFormats[intentName]( witIntents[intentName](entities), entities) return response