def loadflights()

in cloudformation-templates/resources/Lambda/update-flight-LasVegasdeparture/flight.py [0:0]


def loadflights(flights, dynamodb=None):
    if not dynamodb:
        dynamodb = boto3.resource('dynamodb')

    table = dynamodb.Table('Flights')
    nb = 0
    with table.batch_writer() as batch:
        for flight in flights:
            nb += 1
            airline_iata = flight['airline_iata']
            arr_iata = flight['arr_iata']
            delayed = flight['delayed']
            dep_gate = flight['dep_gate']
            dep_iata = flight['dep_iata']
            dep_terminal = flight['dep_terminal']
            dep_time = flight['dep_time']
            flight_number = flight['flight_number']
            status = flight['status']
            print('nb: ', nb)
            print("Adding flight:", arr_iata, flight_number)
            try:
                putres = batch.put_item(Item=flight)
                print('putres: ', putres)
            except Exception as e:
                print('error in put item: ', e)
            time.sleep(0.3)