FlightAware Discussions

Querying with SearchBirdsEyeFlight


#1

I am trying to simulate a search in a certain range with the following criteria:
Flights are in the air
Flights have had their position updated recently.

My search string is as follows
payload = (’{= lastPositionTime ’ + timestr + ‘}‘and’ {!= lastPositionTime 0}‘and’{range lat 39.6895 40.1895}‘and’ {range lon -73.1745 -73.6745}‘and’ {true inAir}’)

where timestr is the current Epoch time as a string. However i have been getting odd results which do not seem to be constrained by my search query at all. For example multiple flights out of the range, or at LastPositionTime = 0, or on the ground etc. It seems like my search criteria is not being recognized at all
Anybody have any thoughts or ideas on how to improve my code to get the results i want.


#2

Be sure that your query string is being sent to the server as the correct variable name. If the variable name is wrong then it has the same effect as not being supplied at all. If you include the code you use to invoke the request then we can check that for correctness.


#3
latlowstr = str(latlow)
lathighstr = str(lathigh)
longlowstr = str(longlow)
longhighstr = str(longhigh)
timet = time.time()
timestr = str(timet)

payload = ('{= lastPositionTime ' + timestr + '}'and' {!= lastPositionTime 0}'and'{range lat ' + latlowstr + ' ' + lathighstr + '}'and' {range lon ' + longlowstr + ' ' + longhighstr + '}'and' {> gs 0}'and' {true inAir}')
try:
    response = requests.get(fxmlUrl + "SearchBirdseyeInFlight", params=payload, auth=(username, apiKey))
    print(response.json())
    decodedResponse = response.json()
    with open('TestCase1', "a") as file:
        file.write(json.dumps(decodedResponse, indent=2, sort_keys=True))


except requests.exceptions.HTTPError as e:
    print(e)

Here is the snippet of my code making the request. I use variables for lat and long. Is my query string currently the incorrect name?


#4

Your params dictionary needs to include an element named “query” that contains your search expression. (You similarly might also want to include “howMany” element in that dictionary to control how many results are returned, but a default will be assumed if you don’t.)

I’ll also recommend that you search for “{>= lastPositionTime xxxxxx}” rather than just equality. Then on your next loop you can repeat your query again with the highest timestamp you last received in your response.


#5

Thanks for your quick responses! I’ve gotten my query to work however now i have been receiving the error:
{‘error’: ‘no data available’}
Which seems unusual as i have been trying to work in the vicinity of Newark Airport where i would assume there is a lot of live traffic.
The URL i am using is:
http://flightxml.flightaware.com/json/FlightXML2/SearchBirdseyeInFlight?query={>=%20lastPositionTime%201540077305.7877908}%20{range%20lat%2039.6963%2040.6963}%20{range%20lon%2073.1813%2074.1813}%20{true%20inAir}

Is this an error from my query or is live data hard to come by?


#6

From doing some quick testing it seems that strings which concatenate multiple search strings do not yield any results. I’ve tried using ‘and’ to connect search terms as well and still do not yield any results


#7

Multiple terms should be combinable by simply separating each curly-bracketed expression with a space. They are automatically combined with logical-AND. (Do not attempt to include the word “and” in the search expression.)

Try specifying a lastPositionTime that is whole integer seconds, rather than a decimal value. Also try specifying a time that is a minute in the past, rather than with your current timestamp, since data is only available in our system with a slight transmission delay (generally less than a couple minutes).