def fetch(self, search_params=None): try: self.search_params = search_params or self.get_search_params() self.search_params_encoded = security.json_encrypt(self.search_params) self.cabin = self.search_params['CabinType'].lower() self.num_travelers = self.search_params['AdultCount'][:1] self.build_airport_list() current_app.logger.debug(self.search_params) self.cache_key = ''.join([value for key, value in self.search_params.items()]) cached = cache.get(self.cache_key) if not cached: response = requests.post(URLS.search_by_schedule, data=self.search_params) content = response.content current_app.logger.debug("Caching Alaska search.") else: content = cached current_app.logger.debug("Found Alaska search in cache.") cache.set(self.cache_key, content, timeout=3600) return content except Exception as e: current_app.logger.error(e) self.abort()
def fetch(self): self.submit_attempts += 1 if self.ticket_code and self.last_name: pass elif self.request.form: self.last_name = self.request.form['name'] self.ticket_code = self.request.form['code'] else: self.abort() try: values = dict( TravelerLastName = self.last_name, CodeOrNumber = self.ticket_code, Continue = 'Continue' ) self.cache_key = ''.join([v for k, v in values.items()]) cached = cache.get(self.cache_key) if not cached: current_app.logger.debug('Requesting {} {}'.format(URLS.lookup_reservation, values)) response = requests.post(URLS.lookup_reservation, data=values) content = response.content current_app.logger.debug("Caching Alaska reservation search.") else: content = cached current_app.logger.debug("Found Alaska reservation in cache.") cache.set(self.cache_key, content, timeout=3600) return content except Exception as e: current_app.logger.error(e) self.abort()