def checkin_job(reservation_id): from swautocheckin.models import Reservation reservation = Reservation.objects.get(id=reservation_id) LOGGER.info("Attempting checkin for " + reservation.__str__()) LOGGER.info('Attempt: ' + str(checkin_job.request.retries + 1)) response_code, boarding_position = checkin.attempt_checkin( reservation.confirmation_num, reservation.passenger.first_name, reservation.passenger.last_name, reservation.passenger.email) try: if response_code == RESPONSE_STATUS_SUCCESS.code: LOGGER.info("Successfully checked in for reservation: " + reservation.__str__()) LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) reservation.success = True reservation.boarding_position = boarding_position reservation.save() return True elif response_code == RESPONSE_STATUS_TOO_EARLY.code: LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) _retry_checkin(reservation) elif response_code == RESPONSE_STATUS_INVALID.code: LOGGER.error("Invalid reservation, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RES_NOT_FOUND.code: LOGGER.error("Reservation not found, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RESERVATION_CANCELLED.code: LOGGER.error("Reservation canceled, id: " + str(reservation.id)) _checkin_fail(reservation) return False else: LOGGER.error("Unknown error, retrying...") _retry_checkin(reservation) except Exception as e: email_subject = "Exception while checking in..." non_html_email_body = "Exception occurred while checking in for " + reservation.id + ": " + e.message send_mail(email_subject, non_html_email_body, settings.EMAIL_HOST_USER, ['*****@*****.**'], fail_silently=False, html_message=non_html_email_body)
def checkin_job(reservation_id): from swautocheckin.models import Reservation reservation = Reservation.objects.get(id=reservation_id) LOGGER.info("Attempting checkin for " + reservation.__str__()) LOGGER.info('Attempt: ' + str(checkin_job.request.retries + 1)) response_code, boarding_position = checkin.attempt_checkin(reservation.confirmation_num, reservation.passenger.first_name, reservation.passenger.last_name, reservation.passenger.email) try: if response_code == RESPONSE_STATUS_SUCCESS.code: LOGGER.info("Successfully checked in for reservation: " + reservation.__str__()) LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) reservation.success = True reservation.boarding_position = boarding_position reservation.save() return True elif response_code == RESPONSE_STATUS_TOO_EARLY.code: LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) _retry_checkin(reservation) elif response_code == RESPONSE_STATUS_INVALID.code: LOGGER.error("Invalid reservation, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RES_NOT_FOUND.code: LOGGER.error("Reservation not found, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RESERVATION_CANCELLED.code: LOGGER.error("Reservation canceled, id: " + str(reservation.id)) _checkin_fail(reservation) return False else: LOGGER.error("Unknown error, retrying...") _retry_checkin(reservation) except Exception as e: email_subject = "Exception while checking in..." non_html_email_body = "Exception occurred while checking in for " + reservation.id + ": " + e.message send_mail(email_subject, non_html_email_body, settings.EMAIL_HOST_USER, ['*****@*****.**'], fail_silently=False, html_message=non_html_email_body)
def clean(self): cleaned_data = super(ReservationForm, self).clean() email = cleaned_data.get("email") first_name = cleaned_data.get("first_name") last_name = cleaned_data.get("last_name") conf_num = cleaned_data.get("confirmation_num") return_flight_time = cleaned_data.get("return_flight_time") return_flight_date = cleaned_data.get("return_flight_date") if return_flight_time and not return_flight_date: msg = u"Required with return flight time." self._errors["return_flight_date"] = self.error_class([msg]) if return_flight_date and not return_flight_time: msg = u"Required with return flight date." self._errors["return_flight_time"] = self.error_class([msg]) if first_name and last_name and conf_num: response_code, boarding_position = checkin.attempt_checkin( conf_num, first_name, last_name, email, do_checkin=False) if response_code is RESPONSE_STATUS_INVALID.code: msg = u"Invalid confirmation code." self._errors["confirmation_num"] = self.error_class([msg]) del cleaned_data["confirmation_num"] elif response_code is RESPONSE_STATUS_RES_NOT_FOUND.code: # used to mean that the res didn't exist, but now it is used for too early as well, so create checkin LOGGER.info("Reservation not found...") pass elif response_code is RESPONSE_STATUS_INVALID_PASSENGER_NAME.code: raise forms.ValidationError( "Passenger name does not match confirmation code.") elif response_code is RESPONSE_STATUS_SUCCESS.code: pass # todo handle successful checkin elif response_code is RESPONSE_STATUS_TOO_EARLY.code: pass else: raise forms.ValidationError( "Error while looking up reservation.") # Always return the full collection of cleaned data. return cleaned_data
def checkin_job(reservation_id): from swautocheckin.models import Reservation reservation = Reservation.objects.get(id=reservation_id) LOGGER.info("Attempting checkin for " + reservation.__str__()) LOGGER.info('Attempt: ' + str(checkin_job.request.retries + 1)) response_code, boarding_position = checkin.attempt_checkin(reservation.confirmation_num, reservation.passenger.first_name, reservation.passenger.last_name, reservation.passenger.email) if response_code == RESPONSE_STATUS_SUCCESS.code: LOGGER.info("Successfully checked in for reservation: " + reservation.__str__()) LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) reservation.success = True reservation.boarding_position = boarding_position reservation.save() return True elif response_code == RESPONSE_STATUS_TOO_EARLY.code: LOGGER.info('Time: ' + str(datetime.now().time())) LOGGER.info('Reservation time: ' + str(reservation.flight_time)) _retry_checkin(reservation) elif response_code == RESPONSE_STATUS_INVALID.code: LOGGER.error("Invalid reservation, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RES_NOT_FOUND.code: LOGGER.error("Reservation not found, id: " + str(reservation.id)) _checkin_fail(reservation) return False elif response_code == RESPONSE_STATUS_RESERVATION_CANCELLED.code: LOGGER.error("Reservation canceled, id: " + str(reservation.id)) _checkin_fail(reservation) return False else: LOGGER.error("Unknown error, retrying...") _retry_checkin(reservation)
def clean(self): cleaned_data = super(ReservationForm, self).clean() email = cleaned_data.get("email") first_name = cleaned_data.get("first_name") last_name = cleaned_data.get("last_name") conf_num = cleaned_data.get("confirmation_num") return_flight_time = cleaned_data.get("return_flight_time") return_flight_date = cleaned_data.get("return_flight_date") if return_flight_time and not return_flight_date: msg = u"Required with return flight time." self._errors["return_flight_date"] = self.error_class([msg]) if return_flight_date and not return_flight_time: msg = u"Required with return flight date." self._errors["return_flight_time"] = self.error_class([msg]) if first_name and last_name and conf_num: response_code, boarding_position = checkin.attempt_checkin(conf_num, first_name, last_name, email, do_checkin=False) if response_code is RESPONSE_STATUS_INVALID.code: msg = u"Invalid confirmation code." self._errors["confirmation_num"] = self.error_class([msg]) del cleaned_data["confirmation_num"] elif response_code is RESPONSE_STATUS_RES_NOT_FOUND.code: # used to mean that the res didn't exist, but now it is used for too early as well, so create checkin LOGGER.info("Reservation not found...") pass elif response_code is RESPONSE_STATUS_INVALID_PASSENGER_NAME.code: raise forms.ValidationError("Passenger name does not match confirmation code.") elif response_code is RESPONSE_STATUS_SUCCESS.code: pass # todo handle successful checkin elif response_code is RESPONSE_STATUS_TOO_EARLY.code: pass else: raise forms.ValidationError("Error while looking up reservation.") # Always return the full collection of cleaned data. return cleaned_data