def auto_checkin(threads, reservation_number, first_name, last_name, prikey, verbose=False): r = Reservation(reservation_number, first_name, last_name, verbose) body = r.lookup_existing_reservation() # Get our local current time now = datetime.utcnow().replace(tzinfo=utc) tomorrow = now + timedelta(days=1) # find all eligible legs for checkin for leg in body['bounds']: # calculate departure for this leg airport = "{}, {}".format(leg['departureAirport']['name'], leg['departureAirport']['state']) takeoff = "{} {}".format(leg['departureDate'], leg['departureTime']) airport_tz = openflights.timezone_for_airport( leg['departureAirport']['code']) date = airport_tz.localize(datetime.strptime(takeoff, '%Y-%m-%d %H:%M')) if date > now: # found a flight for checkin! print(("Flight information found, departing {} at {}".format( airport, date.strftime('%b %d %I:%M%p')))) # Checkin with a thread t = Thread(target=schedule_checkin, args=(date, r, prikey)) t.daemon = True t.start() threads.append(t) # Need to go to the next conf so send back threads to manage return threads
def lookup_reservation(reservation_number, first_name, last_name, verbose=False): r = Reservation(reservation_number, first_name, last_name, verbose) body = r.lookup_existing_reservation() # Get our local current time now = datetime.utcnow().replace(tzinfo=timezone.utc) tomorrow = now + timedelta(days=1) flight_times = [] # find all eligible legs for checkin for leg in body["bounds"]: # calculate departure for this leg airport = "{}, {}".format(leg["departureAirport"]["name"], leg["departureAirport"]["state"]) takeoff = "{} {}".format(leg["departureDate"], leg["departureTime"]) airport_tz = openflights.timezone_for_airport( leg["departureAirport"]["code"]) date = airport_tz.localize(datetime.strptime(takeoff, "%Y-%m-%d %H:%M")) if date > now: # found a flight for checkin! print("Flight information found, departing {} at {}".format( airport, date.strftime("%b %d %I:%M%p"))) flight_times.append(date) return r, flight_times
def set_takeoff(reservation_number, first_name, last_name, verbose=False): r = Reservation(reservation_number, first_name, last_name, verbose) body = r.lookup_existing_reservation() # connect to db to store date db = flights_db.connect() cursor = db.cursor(dictionary=True) i = 0 # find all eligible legs for checkin for leg in body['bounds']: # calculate departure for this leg print("calc departure in leg") airport = "{}, {}".format(leg['departureAirport']['name'], leg['departureAirport']['state']) takeoff = "{} {}".format(leg['departureDate'], leg['departureTime']) for item in leg['flights']: flightnum = item['number'] airport_tz = openflights.timezone_for_airport( leg['departureAirport']['code']) # need to convert this to computer time so we start checkin at the right time cpu_tz = openflights.timezone_for_airport('DEN') temp = airport_tz.localize(datetime.strptime(takeoff, '%Y-%m-%d %H:%M')) date = temp.astimezone(cpu_tz) if i == 0: query = "UPDATE flightinfo SET takeoff=%s, flightnum=%s WHERE conf=%s" cursor.execute(query, (date, flightnum, reservation_number)) db.commit() else: query = "INSERT INTO flightinfo (takeoff, flightnum, conf, first, last) VALUES (%s, %s, %s, %s, %s)" cursor.execute( query, (date, flightnum, reservation_number, first_name, last_name)) db.commit() i += 1 db.close() return ()
def auto_checkin(reservation_number, first_name, last_name, email_address=None, verbose=True): reservation = Reservation(reservation_number, first_name, last_name, verbose) body = reservation.lookup_existing_reservation() # Get our local current time now = datetime.utcnow().replace(tzinfo=utc) tomorrow = now + timedelta(days=1) leg_id_to_threads = dict() # find all eligible legs for checkin for leg in body['bounds']: # calculate departure for this leg airport = "{}, {}".format(leg['departureAirport']['name'], leg['departureAirport']['state']) takeoff = "{} {}".format(leg['departureDate'], leg['departureTime']) departure_airport = leg['departureAirport']['code'] destination_airport = leg['destinationAirport']['code'] airport_tz = openflights.timezone_for_airport( leg['departureAirport']['code']) date = airport_tz.localize(datetime.strptime(takeoff, '%Y-%m-%d %H:%M')) leg_id = '{}.{}.{}.{}.{}.{}'.format(reservation_number, first_name, last_name, departure_airport, destination_airport, takeoff) if date > now: # found a flight for checkin! logging.info("Flight information found, departing {} at {}".format( airport, date.strftime('%b %d %I:%M%p'))) # Checkin with a thread t = Thread(target=schedule_checkin, args=(date, reservation)) t.daemon = True t.start() leg_id_to_threads[leg_id] = t reservation_dict = { 'reservation': reservation, 'leg_id_to_threads': leg_id_to_threads, 'reservation_number': reservation_number, 'first_name': first_name, 'last_name': last_name, 'email_address': email_address } return reservation_dict
def auto_checkin(reservation_number, first_name, last_name, email="", verbose=False): r = Reservation(reservation_number, first_name, last_name, verbose) body = r.lookup_existing_reservation() # Get our local current time now = datetime.utcnow().replace(tzinfo=utc) tomorrow = now + timedelta(days=1) threads = [] # find all eligible legs for checkin for leg in body['bounds']: # calculate departure for this leg airport = "{}, {}".format(leg['departureAirport']['name'], leg['departureAirport']['state']) takeoff = "{} {}".format(leg['departureDate'], leg['departureTime']) airport_tz = openflights.timezone_for_airport( leg['departureAirport']['code']) date = airport_tz.localize(datetime.strptime(takeoff, '%Y-%m-%d %H:%M')) if date > now: # found a flight for checkin! print("Flight information found, departing {} at {}".format( airport, date.strftime('%b %d %I:%M%p'))) # Checkin with a thread t = Thread(target=schedule_checkin, args=(date, r, email)) t.daemon = True t.start() threads.append(t) time.sleep(0.2) print("No more flights associated with this reservation") # cleanup threads while handling Ctrl+C while True: if len(threads) == 0: break for t in threads: t.join(5) if not t.is_alive(): threads.remove(t) break
def _auto_checkin(reservation_number, first_name, last_name, notify=[]): r = Reservation(reservation_number, first_name, last_name, notify) body = r.lookup_existing_reservation() if body is None: my_logger.warning("Giving up on " + reservation_number) return # Get our local current time now = datetime.utcnow().replace(tzinfo=utc) tomorrow = now + timedelta(days=1) threads = [] # find all eligible legs for checkin for leg in body["bounds"]: # calculate departure for this leg airport = "{}, {}".format(leg["departureAirport"]["name"], leg["departureAirport"]["state"]) takeoff = "{} {}".format(leg["departureDate"], leg["departureTime"]) airport_tz = openflights.timezone_for_airport( leg["departureAirport"]["code"]) date = airport_tz.localize(datetime.strptime(takeoff, "%Y-%m-%d %H:%M")) if date > now: # found a flight for checkin! my_logger.info( "Flight information found, departing {} at {}".format( airport, date.strftime("%b %d %I:%M%p"))) # Checkin with a thread stop_signal = Event() t = Thread(target=schedule_checkin, args=(date, r, stop_signal)) t.daemon = True t.start() threads.append({"thread": t, "signal": stop_signal}) return threads