01234567890123456789012345678901234567890123456789012345678901234567890123456789
18191820182118221823182418251826182718281829183018311832183318341835183618371838 18391840184118421843184418451846184718481849185018511852185318541855185618571858 |
<----SKIPPED LINES---->
Returns:
Two tuple:
- Text representation of the json message from FlightAware.
- Text string of error message, if any
"""
min_query_delay_seconds = 90
global last_query_time
url = 'https://flightaware.com/live/flight/' + flight_number
seconds_since_last_query = time.time() - last_query_time
if seconds_since_last_query < min_query_delay_seconds:
error_msg = (
'Unable to query FA for URL since last query to FA was only %d seconds '
'ago; min of %d seconds needed: %s' % (
seconds_since_last_query, min_query_delay_seconds, url))
Log(error_msg)
return '', error_msg
last_query_time = time.time()
try:
response = requests.get(url)
except requests.exceptions.RequestException as e:
error_msg = 'Unable to query FA for URL due to %s: %s' % (e, url)
Log(error_msg)
return '', error_msg
soup = bs4.BeautifulSoup(response.text, 'html.parser')
l = soup.find_all('script')
flight_script = None
for script in l:
if "trackpollBootstrap" in str(script):
flight_script = str(script)
break
if not flight_script:
error_msg = (
'Unable to find trackpollBootstrap script in page: ' + response.text)
Log(error_msg)
return '', error_msg
first_open_curly_brace = flight_script.find('{')
last_close_curly_brace = flight_script.rfind('}')
<----SKIPPED LINES---->
|
01234567890123456789012345678901234567890123456789012345678901234567890123456789
181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863 |
<----SKIPPED LINES---->
Returns:
Two tuple:
- Text representation of the json message from FlightAware.
- Text string of error message, if any
"""
min_query_delay_seconds = 90
global last_query_time
url = 'https://flightaware.com/live/flight/' + flight_number
seconds_since_last_query = time.time() - last_query_time
if seconds_since_last_query < min_query_delay_seconds:
error_msg = (
'Unable to query FA for URL since last query to FA was only %d seconds '
'ago; min of %d seconds needed: %s' % (
seconds_since_last_query, min_query_delay_seconds, url))
Log(error_msg)
return '', error_msg
last_query_time = time.time()
Log(
'last_query_time: %d; time.time(): %d;'
'seconds_since_last_query: %d; min_query_delay_seconds: %d' % (
last_query_time, time.time(),
seconds_since_last_query, min_query_delay_seconds))
try:
response = requests.get(url)
except requests.exceptions.RequestException as e:
error_msg = 'Unable to query FA for URL due to %s: %s' % (e, url)
Log(error_msg)
return '', error_msg
soup = bs4.BeautifulSoup(response.text, 'html.parser')
l = soup.find_all('script')
flight_script = None
for script in l:
if "trackpollBootstrap" in str(script):
flight_script = str(script)
break
if not flight_script:
error_msg = (
'Unable to find trackpollBootstrap script in page: ' + response.text)
Log(error_msg)
return '', error_msg
first_open_curly_brace = flight_script.find('{')
last_close_curly_brace = flight_script.rfind('}')
<----SKIPPED LINES---->
|