Пример #1
0
 def __geocode(self, context: LexContext):
     try:
         data = self.__geocoder.geocode(context)
         if len(data['results']) == 0:
             raise ValidationError(LexContext.SLOT_CITY, Phrases.provide_city())
         if len(data['results']) > 1:
             raise ValidationError(LexContext.SLOT_AREA, Phrases.provide_area_details())
         context.session['location'] = data['results'][0]['geometry']['location']
         logger.debug("GEOCODE: session={}".format(json.dumps(context.session)))
     except KeyError:
         logger.exception("Unable to load location: {}".format(context.address))
         raise ValidationError(LexContext.SLOT_CITY, Phrases.provide_city())
Пример #2
0
 def validate(self, context: LexContext):
     if not context.city:
         raise ValidationError(LexContext.SLOT_CITY, Phrases.provide_city())
     if context.date and not self.__is_valid_date(context.date):
         raise ValidationError(LexContext.SLOT_DATE, Phrases.provide_date())