def setUp(self): self.ip = '<replace_with_some_ip>' self.qe = query_engine() self.pos = self.qe.get_location_and_coordinates_from_ip(self.ip) #print self.pos self.de = decision_engine() self.redis_service = redis_service()
async def search_engine(req, resp): parameter = await req.media() sentence = parameter["query"] query = query_pre_processor(sentence, bow) similarity_distance = query_engine(query, index) result = query_post_processor(similarity_distance) resp.headers = {"Content-Type": "application/json; charset=utf-8"} resp.content = json.dumps(result[0][0], ensure_ascii=False)
def get(self): remote_ip = self.request.remote_ip if remote_ip: qe = query_engine() pos = qe.get_location_and_coordinates_from_ip(remote_ip) if pos: location = pos['location'] if not location: location = 'unknown' weather_report = qe.get_weather_report(pos) if weather_report: de = decision_engine() decision = de.get_decision(weather_report) if decision is not None: self.write(decision + ' visitor from ' + location +'.') self.write('\n') else: self.write('The weather algorithm has no decision, you are on your own.') else: self.write("We couldn't get a weather report for this location, try later") else: self.write("Apologies, Could not geolocate your machine.") else: self.write("Hmm you don't seem to have an ip, what goes?.")