messageboard-2020-09-27-1435.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









18191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865











                            <----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('}')
  flight_json = flight_script[first_open_curly_brace:last_close_curly_brace+1]
  return flight_json, ''




                            <----SKIPPED LINES---->





01234567890123456789012345678901234567890123456789012345678901234567890123456789









18191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865











                            <----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, timeout=5)
  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('}')
  flight_json = flight_script[first_open_curly_brace:last_close_curly_brace+1]
  return flight_json, ''




                            <----SKIPPED LINES---->