Hello,
I am trying to pull back a full day’s worth of scheduled flights but the dataset being returned is incomplete. It contains only 1005 flights but I am expecting closer to 2500. Please let me know if there is a logical error in my query or if I should try a different approach. Thank you for your help!
carrier = 'UAL'
auth_header = {'x-apikey':apiKey}
# start and end dates for the query
start_date = pd.to_datetime('2023-07-15')
end_date = pd.to_datetime('2023-07-16')
# time delta for each request
time_delta = (end_date - start_date) / 200
for i in range(0,200):
# start and end times for this request
start_time = (start_date + i * time_delta).isoformat()
end_time = (start_date + (i + 1) * time_delta).isoformat()
# payload for this request
payload = {'max_pages': 5, 'start': start_time, 'end': end_time}
# make the request
response = requests.get(apiUrl + f"operators/{carrier}/flights/scheduled",
params=payload, headers=auth_header)
if response.status_code == 200:
print('Success!')
# convert response to json and save to file
df = pd.DataFrame(response.json()["scheduled"])
df.to_csv(f'df_{i}.csv', index = False)
else:
print(response.status_code)
time.sleep(1) # wait for 60 seconds