messageboard-2024-02-03-1519.py
01234567890123456789012345678901234567890123456789012345678901234567890123456789









4567891011121314151617181920212223 2425262728293031323334353637383940414243








366367368369370371372373374375376377378379380381382383384385 386387388389390391392393394395396397398399400401402403404405406407408409410411412 413414415416417418419420421422423424425426427428429430 431432433434435436437438439440441442443444445446447448449450








457458459460461462463464465466467468469470471472473474475476 477478479480481482483484485486 487488489490491492493494495496497498499500501502503504505506 507508509510511512513514515516517518519520521522523524525526 527528529 530531532533534535536537538539540541542543544545546547548549550551552553 554555556557558559560561562563564565566567568569570571572573








20072008200920102011201220132014201520162017201820192020202120222023202420252026  2027202820292030203120322033203420352036203720382039204020412042204320442045204620472048











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




import gc
import io
import json
import math
import multiprocessing
import numbers
import os
import pickle
import queue
import re
import shutil
import signal
import statistics
import sys
import textwrap
import time
import tracemalloc
import types

import bs4

import dateutils
import numpy
import matplotlib
import matplotlib.pyplot
import psutil
import pycurl
import pytz
import requests
import tzlocal
import unidecode

# pylint: disable=line-too-long
from constants import RASPBERRY_PI, MESSAGEBOARD_PATH, WEBSERVER_PATH, SECURE_WEBSERVER_PATH, KEY, SECRET, SUBSCRIPTION_ID, LOCAL_KEY, LOCAL_VESTABOARD_ADDRESS
# pylint: enable=line-too-long

import arduino

if RASPBERRY_PI:
  import gpiozero  # pylint: disable=E0401
  import RPi.GPIO  # pylint: disable=E0401




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




SPEED_UNITS = 'kn'
DISTANCE_UNITS = 'ft'  # altitude

# For displaying histograms
# If a key is not present, how should it be displayed in histograms?
KEY_NOT_PRESENT_STRING = 'Unknown'
OTHER_STRING = 'Other' # What key strings should be listed last in sequence?
# What key strings should be listed last in sequence?
SORT_AT_END_STRINGS = [OTHER_STRING, KEY_NOT_PRESENT_STRING]
# What is the sorted sequence of keys for days of week?
DAYS_OF_WEEK = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

# AIRCRAFT_LENGTH[''] =
AIRCRAFT_LENGTH = {} # in meters

AIRCRAFT_LENGTH['Airbus A220-100 (twin-jet)'] = 35
AIRCRAFT_LENGTH['Airbus A220-300 (twin-jet)'] = 38.71
AIRCRAFT_LENGTH['Airbus A300F4-600 (twin-jet)'] = 54.08
AIRCRAFT_LENGTH['Airbus A319 (twin-jet)'] = 33.84
AIRCRAFT_LENGTH['Airbus A320 (twin-jet)'] = 37.57

AIRCRAFT_LENGTH['Airbus A320neo (twin-jet)'] = 37.57
AIRCRAFT_LENGTH['Airbus A321 (twin-jet)'] = 44.51
AIRCRAFT_LENGTH['Airbus A321neo (twin-jet)'] = 44.51
AIRCRAFT_LENGTH['Airbus A330 (twin-jet)'] = 58.82  # assumed -200 or -300
AIRCRAFT_LENGTH['Airbus A330-200 (twin-jet)'] = 58.82
AIRCRAFT_LENGTH['Airbus A330-300 (twin-jet)'] = 63.67
AIRCRAFT_LENGTH['AIRBUS A-330-900 (twin-jet)'] = 63.66
AIRCRAFT_LENGTH['Airbus A330-900 (twin-jet)'] = 63.66
AIRCRAFT_LENGTH['Airbus A340-300 (quad-jet)'] = 63.69
AIRCRAFT_LENGTH['Airbus A350-1000 (twin-jet)'] = 73.79
AIRCRAFT_LENGTH['Airbus A350-900 (twin-jet)'] = 66.8
AIRCRAFT_LENGTH['Airbus A380-800 (quad-jet)'] = 72.72
AIRCRAFT_LENGTH['Antonov An-124 Ruslan (quad-jet)'] = 69.1
AIRCRAFT_LENGTH['Beechcraft Beechjet (twin-jet)'] = 14.76
AIRCRAFT_LENGTH['Beechcraft Bonanza (33) (piston-single)'] = 7.65
AIRCRAFT_LENGTH['Beechcraft Bonanza (36) (piston-single)'] = 8.38
AIRCRAFT_LENGTH['Beechcraft King Air 90 (twin-turboprop)'] = 10.82
AIRCRAFT_LENGTH['Beechcraft King Air F90 (twin-turboprop)'] = 12.14
AIRCRAFT_LENGTH['Beechcraft Premier 1 (twin-jet)'] = 14.02
AIRCRAFT_LENGTH['Beechcraft Super King Air 200 (twin-turboprop)'] = 13.31
AIRCRAFT_LENGTH['Beechcraft Super King Air 350 (twin-turboprop)'] = 14.22
AIRCRAFT_LENGTH['Bell 429 GlobalRanger (twin-turboshaft)'] = 12.70
AIRCRAFT_LENGTH['Boeing 737-400 (twin-jet)'] = 36.4
AIRCRAFT_LENGTH['Boeing 737-500 (twin-jet)'] = 31.0
AIRCRAFT_LENGTH['Boeing 737-700 (twin-jet)'] = 33.63
AIRCRAFT_LENGTH['Boeing 737-800 (twin-jet)'] = 39.47
AIRCRAFT_LENGTH['Boeing 737-900 (twin-jet)'] = 42.11

AIRCRAFT_LENGTH['Boeing 737 MAX 8 (twin-jet)'] = 39.47
AIRCRAFT_LENGTH['Boeing 737 MAX 9 (twin-jet)'] = 42.1
AIRCRAFT_LENGTH['Boeing 737 MAX 9 (twin-jet)'] = 42.1
AIRCRAFT_LENGTH['Boeing 747-100 (quad-jet)'] = 70.66
AIRCRAFT_LENGTH['Boeing 747-400 (quad-jet)'] = 70.66
AIRCRAFT_LENGTH['Boeing 747-8 (quad-jet)'] = 76.25
AIRCRAFT_LENGTH['Boeing 757-200 (twin-jet)'] = 47.3
AIRCRAFT_LENGTH['Boeing 757-300 (twin-jet)'] = 54.4
AIRCRAFT_LENGTH['Boeing 767-200 (twin-jet)'] = 48.51
AIRCRAFT_LENGTH['BOEING 767-300 (twin-jet)'] = 54.94
AIRCRAFT_LENGTH['Boeing 767-300 (twin-jet)'] = 54.94
AIRCRAFT_LENGTH['BOEING 767-400 (twin-jet)'] = 61.37
AIRCRAFT_LENGTH['Boeing 777 (twin-jet)'] = (63.73 + 73.86) / 2
AIRCRAFT_LENGTH['Boeing 777-200 (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING 777-200ER (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING 777-200LR (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['Boeing 777-200LR/F (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['Boeing 777-300 (twin-jet)'] = 33.4

AIRCRAFT_LENGTH['BOEING 777-300ER (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['Boeing 777-300ER (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['Boeing 787-10 (twin-jet)'] = 68.28
AIRCRAFT_LENGTH['Boeing 787-8 (twin-jet)'] = 56.72
AIRCRAFT_LENGTH['Boeing 787-9 (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['Boeing 787-9 Dreamliner (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['BOEING 787-10 Dreamliner (twin-jet)'] = 68.28
AIRCRAFT_LENGTH['BOEING BBJ (747-8) (quad-jet)'] = 76.25
AIRCRAFT_LENGTH['BOEING BBJ (777-200LR) (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING BBJ (777-300ER) (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['BOEING BBJ3 (twin-jet)'] = 42.11
AIRCRAFT_LENGTH['Boeing Dreamliner (Srs.8) (twin-jet)'] = 56.72
AIRCRAFT_LENGTH['BOEING Dreamliner (Srs.9) (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['Boeing MD-11 (tri-jet)'] = (61.2 + 61.6) / 2
AIRCRAFT_LENGTH['BOMBARDIER BD-700 Global 7500 (twin-jet)'] = 33.88
AIRCRAFT_LENGTH['Bombardier Challenger 300 (twin-jet)'] = 20.92
AIRCRAFT_LENGTH['Bombardier Global 5000 (twin-jet)'] = 29.5
AIRCRAFT_LENGTH['Bombardier Global Express (twin-jet)'] = (29.5 + 30.3) / 2
AIRCRAFT_LENGTH['Bombardier Learjet 75 (twin-jet)'] = 17.7
AIRCRAFT_LENGTH['Canadair Challenger (twin-jet)'] = 20.9




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




AIRCRAFT_LENGTH['Cessna Citation 1SP (twin-jet)'] = 13.26
AIRCRAFT_LENGTH['Cessna Citation Bravo (twin-jet)'] = 14.54
AIRCRAFT_LENGTH['Cessna Citation CJ1 (twin-jet)'] = 12.98
AIRCRAFT_LENGTH['Cessna Citation CJ2+ (twin-jet)'] = 14.53
AIRCRAFT_LENGTH['Cessna Citation CJ3 (twin-jet)'] = 15.59
AIRCRAFT_LENGTH['Cessna Citation CJ4 (twin-jet)'] = 16.26
AIRCRAFT_LENGTH['Cessna Citation M2 (twin-jet)'] = 12.98
AIRCRAFT_LENGTH['Cessna Citation Excel/XLS (twin-jet)'] = 16.0
AIRCRAFT_LENGTH['Cessna Citation II (twin-jet)'] = 14.54
AIRCRAFT_LENGTH['Cessna Citation Latitude (twin-jet)'] = 18.97
AIRCRAFT_LENGTH['Cessna Citation Longitude (twin-jet)'] = 22.3
AIRCRAFT_LENGTH['Cessna Citation Mustang (twin-jet)'] = 12.37
AIRCRAFT_LENGTH['Cessna Citation Sovereign (twin-jet)'] = 19.35
AIRCRAFT_LENGTH['Cessna Citation V (twin-jet)'] = 14.91
AIRCRAFT_LENGTH['Cessna Citation X (twin-jet)'] = 22.04
AIRCRAFT_LENGTH['Cessna Conquest 2 (twin-turboprop)'] = 11.89
AIRCRAFT_LENGTH['Cessna Skyhawk (piston-single)'] = 8.28
AIRCRAFT_LENGTH['Cessna Skylane (piston-single)'] = 8.84
AIRCRAFT_LENGTH['CESSNA T182 Turbo Skylane (piston-single)'] = 8.84
AIRCRAFT_LENGTH['Cessna T206 Turbo Stationair (piston-single)'] = 8.61

AIRCRAFT_LENGTH['Cessna 421 (twin-piston)'] = 11.09
AIRCRAFT_LENGTH['Cirrus SR-20 (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus SR-22 (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus SR22 Turbo (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus Vision SF50 (single-jet)'] = 9.42
AIRCRAFT_LENGTH['Daher-Socata TBM-900 (single-turboprop)'] = 10.72
AIRCRAFT_LENGTH['Dassault Falcon 50 (tri-jet)'] = 18.52
AIRCRAFT_LENGTH['Dassault Falcon 7X (tri-jet)'] = 23.38
AIRCRAFT_LENGTH['Dassault Falcon 2000 (twin-jet)'] = 20.23
AIRCRAFT_LENGTH['Dassault Falcon 900 (tri-jet)'] = 20.21

AIRCRAFT_LENGTH['Embraer 170/175 (twin-jet)'] = (29.90 + 31.68) / 2
AIRCRAFT_LENGTH['EMBRAER 175 (long wing) (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['EMBRAER 195 (twin-jet)'] = 38.66
AIRCRAFT_LENGTH['Embraer ERJ-135 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer ERJ-145 (twin-jet)'] = 29.87
AIRCRAFT_LENGTH['Embraer ERJ 175 (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['Embraer ERJ 190 (twin-jet)'] = 36.25
AIRCRAFT_LENGTH['Embraer ERJ-190 (twin-jet)'] = 36.25
AIRCRAFT_LENGTH['Embraer Legacy 450 (twin-jet)'] = 19.69
AIRCRAFT_LENGTH['Embraer Legacy 550 (twin-jet)'] = 20.74
AIRCRAFT_LENGTH['Embraer Legacy 600/650 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer Phenom 100 (twin-jet)'] = 12.82
AIRCRAFT_LENGTH['Embraer Phenom 300 (twin-jet)'] = 15.9
AIRCRAFT_LENGTH['Epic Aircraft LT (single-turboprop)'] = 10.92
AIRCRAFT_LENGTH['Eurocopter EC-635 (twin-turboshaft)'] = 10.21
AIRCRAFT_LENGTH['Fairchild Dornier 328JET (twin-jet)'] = 21.11
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 25.32
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G450 (twin-jet)'] = 27.23
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 29.39
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G650 (twin-jet)'] = 30.41

AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 26.92
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 29.4
AIRCRAFT_LENGTH['GULFSTREAM AEROSPACE G-7 Gulfstream G600 (twin-jet)'] = 29.29
AIRCRAFT_LENGTH['Hawker Beechcraft 4000 (twin-jet)'] = 21.08
AIRCRAFT_LENGTH['Honda HondaJet (twin-jet)'] = 12.99
AIRCRAFT_LENGTH['IAI Gulfstream G100 (twin-jet)'] = 16.94
AIRCRAFT_LENGTH['IAI Gulfstream G150 (twin-jet)'] = 16.94
AIRCRAFT_LENGTH['IAI Gulfstream G200 (twin-jet)'] = 18.97
AIRCRAFT_LENGTH['IAI Gulfstream G280 (twin-jet)'] = 20.3
AIRCRAFT_LENGTH['Learjet 31 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 35 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 40 (twin-jet)'] = 16.92
AIRCRAFT_LENGTH['Learjet 45 (twin-jet)'] = 17.68
AIRCRAFT_LENGTH['Learjet 55 (twin-jet)'] = 16.79
AIRCRAFT_LENGTH['Learjet 60 (twin-jet)'] = 17.88
AIRCRAFT_LENGTH['McDonnell Douglas MD-11 (tri-jet)'] = 61.6
AIRCRAFT_LENGTH['McDonnell Douglas MD-83 (twin-jet)'] = 45.06
AIRCRAFT_LENGTH['Mooney M-20 (piston-single)'] = 8.13
AIRCRAFT_LENGTH['North American Navion (piston-single)'] = 8.38
AIRCRAFT_LENGTH['North American Sabreliner (twin-jet)'] = 13.41

AIRCRAFT_LENGTH['Pilatus PC-12 (single-turboprop)'] = 14.4
AIRCRAFT_LENGTH['Pilatus PC-24 (twin-jet)'] = 16.85
AIRCRAFT_LENGTH['Piper Cherokee (piston-single)'] = 7.10

AIRCRAFT_LENGTH['Piper Navajo (twin-piston)'] = 9.94
AIRCRAFT_LENGTH['Raytheon Hawker 800 (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 800XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 850XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 900XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 1000 (twin-jet)'] = 16.08
AIRCRAFT_LENGTH['Rockwell Turbo Commander 690 (twin-turboprop)'] = 11.22
for mixed_case_plane in list(AIRCRAFT_LENGTH.keys()):  # pylint: disable=C0201
  AIRCRAFT_LENGTH[mixed_case_plane.upper()] = AIRCRAFT_LENGTH[mixed_case_plane]
  AIRCRAFT_LENGTH.pop(mixed_case_plane)

# pylint: disable=line-too-long
SHORTER_AIRCRAFT_NAME = {}
SHORTER_AIRCRAFT_NAME['Boeing 787-9 Dreamliner (twin-jet)'] = 'Boeing 787-9 (twin-jet)'
SHORTER_AIRCRAFT_NAME['BOEING 787-10 Dreamliner (twin-jet)'] = 'Boeing 787-10 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-200 (twin-jet)'] = 'Canadair CRJ-200 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-700 (twin-jet)'] = 'Canadair CRJ-700 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-900 (twin-jet)'] = 'Canadair CRJ-900 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 'Gulfstream 3 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream G450 (twin-jet)'] = 'Gulfstream G450 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 'Gulfstream G550 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 'Gulfstream IV (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 'Gulfstream V (twin-jet)'
SHORTER_AIRCRAFT_NAME['GULFSTREAM AEROSPACE G-7 Gulfstream G600 (twin-jet)'] = 'Gulfstream G600 (twin-jet)'

# pylint: enable=line-too-long

SHORTER_AIRLINE_NAME = {}
SHORTER_AIRLINE_NAME['WHEELS UP - GAMA AVIATION'] = 'GAMA AVIATION'


def Log(message, file=None, rolling=None):
  """Write a message to a logfile along with a timestamp.

  Args:
    message: string message to write
    file: string representing file name and, if needed, path to the
      file to write to
    rolling: name of file that will keep only the last n files of file
  """
  # can't define as a default parameter because LOGFILE name is potentially
  # modified based on SIMULATION flag
  if not file:
    file = LOGFILE





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





  global last_query_time
  global last_query_flight_number
  seconds_since_last_query = time.time() - last_query_time
  if last_query_time and seconds_since_last_query < min_query_delay_seconds:
    error_msg = (
        'Unable to query FA for %s at %s since last query to FA was only'
        ' %d seconds ago for %s; min of %d seconds needed: %s' % (
            flight_number,
            EpochDisplayTime(time.time(), format_string='%H:%M:%S'),
            seconds_since_last_query,
            last_query_flight_number,
            min_query_delay_seconds,
            url))
    flight_aware_status_code = 'WARNING'
    return '', error_msg, flight_aware_status_code, time.time()

  last_query_time = time.time()
  last_query_flight_number = flight_number



  try:
    response = requests.get(url, timeout=5)
    query_time = time.time()
  except requests.exceptions.RequestException as e:
    query_time = time.time()  # did not get to the query_time assignment above
    error_msg = 'Unable to query FA for URL due to %s: %s' % (e, url)
    flight_aware_status_code = 'FAILURE'
    return '', error_msg, flight_aware_status_code, query_time

  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)
    flight_aware_status_code = 'FAILURE'
    return '', error_msg, flight_aware_status_code, query_time




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





01234567890123456789012345678901234567890123456789012345678901234567890123456789









4567891011121314151617181920212223242526272829303132333435363738394041424344








367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454








461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583








20172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060











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




import gc
import io
import json
import math
import multiprocessing
import numbers
import os
import pickle
import queue
import re
import shutil
import signal
import statistics
import sys
import textwrap
import time
import tracemalloc
import types

import bs4
import cloudscraper
import dateutils
import numpy
import matplotlib
import matplotlib.pyplot
import psutil
import pycurl
import pytz
import requests
import tzlocal
import unidecode

# pylint: disable=line-too-long
from constants import RASPBERRY_PI, MESSAGEBOARD_PATH, WEBSERVER_PATH, SECURE_WEBSERVER_PATH, KEY, SECRET, SUBSCRIPTION_ID, LOCAL_KEY, LOCAL_VESTABOARD_ADDRESS
# pylint: enable=line-too-long

import arduino

if RASPBERRY_PI:
  import gpiozero  # pylint: disable=E0401
  import RPi.GPIO  # pylint: disable=E0401




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




SPEED_UNITS = 'kn'
DISTANCE_UNITS = 'ft'  # altitude

# For displaying histograms
# If a key is not present, how should it be displayed in histograms?
KEY_NOT_PRESENT_STRING = 'Unknown'
OTHER_STRING = 'Other' # What key strings should be listed last in sequence?
# What key strings should be listed last in sequence?
SORT_AT_END_STRINGS = [OTHER_STRING, KEY_NOT_PRESENT_STRING]
# What is the sorted sequence of keys for days of week?
DAYS_OF_WEEK = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

# AIRCRAFT_LENGTH[''] =
AIRCRAFT_LENGTH = {} # in meters

AIRCRAFT_LENGTH['Airbus A220-100 (twin-jet)'] = 35
AIRCRAFT_LENGTH['Airbus A220-300 (twin-jet)'] = 38.71
AIRCRAFT_LENGTH['Airbus A300F4-600 (twin-jet)'] = 54.08
AIRCRAFT_LENGTH['Airbus A319 (twin-jet)'] = 33.84
AIRCRAFT_LENGTH['Airbus A320 (twin-jet)'] = 37.57
AIRCRAFT_LENGTH['Airbus A320 (jet bimotor)'] = 37.57
AIRCRAFT_LENGTH['Airbus A320neo (twin-jet)'] = 37.57
AIRCRAFT_LENGTH['Airbus A321 (twin-jet)'] = 44.51
AIRCRAFT_LENGTH['Airbus A321neo (twin-jet)'] = 44.51
AIRCRAFT_LENGTH['Airbus A330 (twin-jet)'] = 58.82  # assumed -200 or -300
AIRCRAFT_LENGTH['Airbus A330-200 (twin-jet)'] = 58.82
AIRCRAFT_LENGTH['Airbus A330-300 (twin-jet)'] = 63.67
AIRCRAFT_LENGTH['AIRBUS A-330-900 (twin-jet)'] = 63.66
AIRCRAFT_LENGTH['Airbus A330-900 (twin-jet)'] = 63.66
AIRCRAFT_LENGTH['Airbus A340-300 (quad-jet)'] = 63.69
AIRCRAFT_LENGTH['Airbus A350-1000 (twin-jet)'] = 73.79
AIRCRAFT_LENGTH['Airbus A350-900 (twin-jet)'] = 66.8
AIRCRAFT_LENGTH['Airbus A380-800 (quad-jet)'] = 72.72
AIRCRAFT_LENGTH['Antonov An-124 Ruslan (quad-jet)'] = 69.1
AIRCRAFT_LENGTH['Beechcraft Beechjet (twin-jet)'] = 14.76
AIRCRAFT_LENGTH['Beechcraft Bonanza (33) (piston-single)'] = 7.65
AIRCRAFT_LENGTH['Beechcraft Bonanza (36) (piston-single)'] = 8.38
AIRCRAFT_LENGTH['Beechcraft King Air 90 (twin-turboprop)'] = 10.82
AIRCRAFT_LENGTH['Beechcraft King Air F90 (twin-turboprop)'] = 12.14
AIRCRAFT_LENGTH['Beechcraft Premier 1 (twin-jet)'] = 14.02
AIRCRAFT_LENGTH['Beechcraft Super King Air 200 (twin-turboprop)'] = 13.31
AIRCRAFT_LENGTH['Beechcraft Super King Air 350 (twin-turboprop)'] = 14.22
AIRCRAFT_LENGTH['Bell 429 GlobalRanger (twin-turboshaft)'] = 12.70
AIRCRAFT_LENGTH['Boeing 737-400 (twin-jet)'] = 36.4
AIRCRAFT_LENGTH['Boeing 737-500 (twin-jet)'] = 31.0
AIRCRAFT_LENGTH['Boeing 737-700 (twin-jet)'] = 33.63
AIRCRAFT_LENGTH['Boeing 737-800 (twin-jet)'] = 39.47
AIRCRAFT_LENGTH['Boeing 737-900 (twin-jet)'] = 42.11
AIRCRAFT_LENGTH['Boeing 737-900 (jet bimotor)'] = 42.11
AIRCRAFT_LENGTH['Boeing 737 MAX 8 (twin-jet)'] = 39.47
AIRCRAFT_LENGTH['Boeing 737 MAX 9 (twin-jet)'] = 42.1
AIRCRAFT_LENGTH['Boeing 737 MAX 9 (twin-jet)'] = 42.1
AIRCRAFT_LENGTH['Boeing 747-100 (quad-jet)'] = 70.66
AIRCRAFT_LENGTH['Boeing 747-400 (quad-jet)'] = 70.66
AIRCRAFT_LENGTH['Boeing 747-8 (quad-jet)'] = 76.25
AIRCRAFT_LENGTH['Boeing 757-200 (twin-jet)'] = 47.3
AIRCRAFT_LENGTH['Boeing 757-300 (twin-jet)'] = 54.4
AIRCRAFT_LENGTH['Boeing 767-200 (twin-jet)'] = 48.51
AIRCRAFT_LENGTH['BOEING 767-300 (twin-jet)'] = 54.94
AIRCRAFT_LENGTH['Boeing 767-300 (twin-jet)'] = 54.94
AIRCRAFT_LENGTH['BOEING 767-400 (twin-jet)'] = 61.37
AIRCRAFT_LENGTH['Boeing 777 (twin-jet)'] = (63.73 + 73.86) / 2
AIRCRAFT_LENGTH['Boeing 777-200 (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING 777-200ER (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING 777-200LR (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['Boeing 777-200LR/F (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['Boeing 777-300 (twin-jet)'] = 33.4
AIRCRAFT_LENGTH['BOEING 777-300ER (jet bimotor)'] = 73.86
AIRCRAFT_LENGTH['BOEING 777-300ER (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['Boeing 777-300ER (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['Boeing 787-10 (twin-jet)'] = 68.28
AIRCRAFT_LENGTH['Boeing 787-8 (twin-jet)'] = 56.72
AIRCRAFT_LENGTH['Boeing 787-9 (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['Boeing 787-9 Dreamliner (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['BOEING 787-10 Dreamliner (twin-jet)'] = 68.28
AIRCRAFT_LENGTH['BOEING BBJ (747-8) (quad-jet)'] = 76.25
AIRCRAFT_LENGTH['BOEING BBJ (777-200LR) (twin-jet)'] = 63.73
AIRCRAFT_LENGTH['BOEING BBJ (777-300ER) (twin-jet)'] = 73.86
AIRCRAFT_LENGTH['BOEING BBJ3 (twin-jet)'] = 42.11
AIRCRAFT_LENGTH['Boeing Dreamliner (Srs.8) (twin-jet)'] = 56.72
AIRCRAFT_LENGTH['BOEING Dreamliner (Srs.9) (twin-jet)'] = 62.81
AIRCRAFT_LENGTH['Boeing MD-11 (tri-jet)'] = (61.2 + 61.6) / 2
AIRCRAFT_LENGTH['BOMBARDIER BD-700 Global 7500 (twin-jet)'] = 33.88
AIRCRAFT_LENGTH['Bombardier Challenger 300 (twin-jet)'] = 20.92
AIRCRAFT_LENGTH['Bombardier Global 5000 (twin-jet)'] = 29.5
AIRCRAFT_LENGTH['Bombardier Global Express (twin-jet)'] = (29.5 + 30.3) / 2
AIRCRAFT_LENGTH['Bombardier Learjet 75 (twin-jet)'] = 17.7
AIRCRAFT_LENGTH['Canadair Challenger (twin-jet)'] = 20.9




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




AIRCRAFT_LENGTH['Cessna Citation 1SP (twin-jet)'] = 13.26
AIRCRAFT_LENGTH['Cessna Citation Bravo (twin-jet)'] = 14.54
AIRCRAFT_LENGTH['Cessna Citation CJ1 (twin-jet)'] = 12.98
AIRCRAFT_LENGTH['Cessna Citation CJ2+ (twin-jet)'] = 14.53
AIRCRAFT_LENGTH['Cessna Citation CJ3 (twin-jet)'] = 15.59
AIRCRAFT_LENGTH['Cessna Citation CJ4 (twin-jet)'] = 16.26
AIRCRAFT_LENGTH['Cessna Citation M2 (twin-jet)'] = 12.98
AIRCRAFT_LENGTH['Cessna Citation Excel/XLS (twin-jet)'] = 16.0
AIRCRAFT_LENGTH['Cessna Citation II (twin-jet)'] = 14.54
AIRCRAFT_LENGTH['Cessna Citation Latitude (twin-jet)'] = 18.97
AIRCRAFT_LENGTH['Cessna Citation Longitude (twin-jet)'] = 22.3
AIRCRAFT_LENGTH['Cessna Citation Mustang (twin-jet)'] = 12.37
AIRCRAFT_LENGTH['Cessna Citation Sovereign (twin-jet)'] = 19.35
AIRCRAFT_LENGTH['Cessna Citation V (twin-jet)'] = 14.91
AIRCRAFT_LENGTH['Cessna Citation X (twin-jet)'] = 22.04
AIRCRAFT_LENGTH['Cessna Conquest 2 (twin-turboprop)'] = 11.89
AIRCRAFT_LENGTH['Cessna Skyhawk (piston-single)'] = 8.28
AIRCRAFT_LENGTH['Cessna Skylane (piston-single)'] = 8.84
AIRCRAFT_LENGTH['CESSNA T182 Turbo Skylane (piston-single)'] = 8.84
AIRCRAFT_LENGTH['Cessna T206 Turbo Stationair (piston-single)'] = 8.61
AIRCRAFT_LENGTH['Cessna 310 (twin-piston)'] = 8.23
AIRCRAFT_LENGTH['Cessna 421 (twin-piston)'] = 11.09
AIRCRAFT_LENGTH['Cirrus SR-20 (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus SR-22 (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus SR22 Turbo (piston-single)'] = 7.92
AIRCRAFT_LENGTH['Cirrus Vision SF50 (single-jet)'] = 9.42
AIRCRAFT_LENGTH['Daher-Socata TBM-900 (single-turboprop)'] = 10.72
AIRCRAFT_LENGTH['Dassault Falcon 50 (tri-jet)'] = 18.52
AIRCRAFT_LENGTH['Dassault Falcon 7X (tri-jet)'] = 23.38
AIRCRAFT_LENGTH['Dassault Falcon 2000 (twin-jet)'] = 20.23
AIRCRAFT_LENGTH['Dassault Falcon 900 (tri-jet)'] = 20.21
AIRCRAFT_LENGTH['Diamond Star (piston-single)'] = 8.1
AIRCRAFT_LENGTH['Embraer 170/175 (twin-jet)'] = (29.90 + 31.68) / 2
AIRCRAFT_LENGTH['EMBRAER 175 (long wing) (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['EMBRAER 195 (twin-jet)'] = 38.66
AIRCRAFT_LENGTH['Embraer ERJ-135 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer ERJ-145 (twin-jet)'] = 29.87
AIRCRAFT_LENGTH['Embraer ERJ 175 (twin-jet)'] = 31.68
AIRCRAFT_LENGTH['Embraer ERJ 190 (twin-jet)'] = 36.25
AIRCRAFT_LENGTH['Embraer ERJ-190 (twin-jet)'] = 36.25
AIRCRAFT_LENGTH['Embraer Legacy 450 (twin-jet)'] = 19.69
AIRCRAFT_LENGTH['Embraer Legacy 550 (twin-jet)'] = 20.74
AIRCRAFT_LENGTH['Embraer Legacy 600/650 (twin-jet)'] = 26.33
AIRCRAFT_LENGTH['Embraer Phenom 100 (twin-jet)'] = 12.82
AIRCRAFT_LENGTH['Embraer Phenom 300 (twin-jet)'] = 15.9
AIRCRAFT_LENGTH['Epic Aircraft LT (single-turboprop)'] = 10.92
AIRCRAFT_LENGTH['Eurocopter EC-635 (twin-turboshaft)'] = 10.21
AIRCRAFT_LENGTH['Fairchild Dornier 328JET (twin-jet)'] = 21.11
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 25.32
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G450 (twin-jet)'] = 27.23
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 29.39
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G650 (twin-jet)'] = 30.41
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream G-7 (twin-jet)'] = 33.48
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 26.92
AIRCRAFT_LENGTH['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 29.4
AIRCRAFT_LENGTH['GULFSTREAM AEROSPACE G-7 Gulfstream G600 (twin-jet)'] = 29.29
AIRCRAFT_LENGTH['Hawker Beechcraft 4000 (twin-jet)'] = 21.08
AIRCRAFT_LENGTH['Honda HondaJet (twin-jet)'] = 12.99
AIRCRAFT_LENGTH['IAI Gulfstream G100 (twin-jet)'] = 16.94
AIRCRAFT_LENGTH['IAI Gulfstream G150 (twin-jet)'] = 16.94
AIRCRAFT_LENGTH['IAI Gulfstream G200 (twin-jet)'] = 18.97
AIRCRAFT_LENGTH['IAI Gulfstream G280 (twin-jet)'] = 20.3
AIRCRAFT_LENGTH['Learjet 31 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 35 (twin-jet)'] = 14.83
AIRCRAFT_LENGTH['Learjet 40 (twin-jet)'] = 16.92
AIRCRAFT_LENGTH['Learjet 45 (twin-jet)'] = 17.68
AIRCRAFT_LENGTH['Learjet 55 (twin-jet)'] = 16.79
AIRCRAFT_LENGTH['Learjet 60 (twin-jet)'] = 17.88
AIRCRAFT_LENGTH['McDonnell Douglas MD-11 (tri-jet)'] = 61.6
AIRCRAFT_LENGTH['McDonnell Douglas MD-83 (twin-jet)'] = 45.06
AIRCRAFT_LENGTH['Mooney M-20 (piston-single)'] = 8.13
AIRCRAFT_LENGTH['North American Navion (piston-single)'] = 8.38
AIRCRAFT_LENGTH['North American Sabreliner (twin-jet)'] = 13.41
AIRCRAFT_LENGTH['Piaggio P.180 Avanti (twin-turboprop)'] = 47.3
AIRCRAFT_LENGTH['Pilatus PC-12 (single-turboprop)'] = 14.4
AIRCRAFT_LENGTH['Pilatus PC-24 (twin-jet)'] = 16.85
AIRCRAFT_LENGTH['Piper Cherokee (piston-single)'] = 7.10
AIRCRAFT_LENGTH['Piper Malibu Meridian (single-turboprop)'] = 9.02
AIRCRAFT_LENGTH['Piper Navajo (twin-piston)'] = 9.94
AIRCRAFT_LENGTH['Raytheon Hawker 800 (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 800XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 850XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 900XP (twin-jet)'] = 15.60
AIRCRAFT_LENGTH['Raytheon Hawker 1000 (twin-jet)'] = 16.08
AIRCRAFT_LENGTH['Rockwell Turbo Commander 690 (twin-turboprop)'] = 11.22
for mixed_case_plane in list(AIRCRAFT_LENGTH.keys()):  # pylint: disable=C0201
  AIRCRAFT_LENGTH[mixed_case_plane.upper()] = AIRCRAFT_LENGTH[mixed_case_plane]
  AIRCRAFT_LENGTH.pop(mixed_case_plane)

# pylint: disable=line-too-long
SHORTER_AIRCRAFT_NAME = {}
SHORTER_AIRCRAFT_NAME['Boeing 787-9 Dreamliner (twin-jet)'] = 'Boeing 787-9 (twin-jet)'
SHORTER_AIRCRAFT_NAME['BOEING 787-10 Dreamliner (twin-jet)'] = 'Boeing 787-10 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-200 (twin-jet)'] = 'Canadair CRJ-200 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-700 (twin-jet)'] = 'Canadair CRJ-700 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Canadair Regional Jet CRJ-900 (twin-jet)'] = 'Canadair CRJ-900 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream 3 (twin-jet)'] = 'Gulfstream 3 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream G450 (twin-jet)'] = 'Gulfstream G450 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream G550 (twin-jet)'] = 'Gulfstream G550 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream IV (twin-jet)'] = 'Gulfstream IV (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream V (twin-jet)'] = 'Gulfstream V (twin-jet)'
SHORTER_AIRCRAFT_NAME['GULFSTREAM AEROSPACE G-7 Gulfstream G600 (twin-jet)'] = 'Gulfstream G600 (twin-jet)'
SHORTER_AIRCRAFT_NAME['Gulfstream Aerospace Gulfstream G-7 (twin-jet)'] = 'Gulfstream G-7 (twin-jet)'
# pylint: enable=line-too-long

SHORTER_AIRLINE_NAME = {}
SHORTER_AIRLINE_NAME['WHEELS UP - GAMA AVIATION'] = 'GAMA AVIATION'


def Log(message, file=None, rolling=None):
  """Write a message to a logfile along with a timestamp.

  Args:
    message: string message to write
    file: string representing file name and, if needed, path to the
      file to write to
    rolling: name of file that will keep only the last n files of file
  """
  # can't define as a default parameter because LOGFILE name is potentially
  # modified based on SIMULATION flag
  if not file:
    file = LOGFILE





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





  global last_query_time
  global last_query_flight_number
  seconds_since_last_query = time.time() - last_query_time
  if last_query_time and seconds_since_last_query < min_query_delay_seconds:
    error_msg = (
        'Unable to query FA for %s at %s since last query to FA was only'
        ' %d seconds ago for %s; min of %d seconds needed: %s' % (
            flight_number,
            EpochDisplayTime(time.time(), format_string='%H:%M:%S'),
            seconds_since_last_query,
            last_query_flight_number,
            min_query_delay_seconds,
            url))
    flight_aware_status_code = 'WARNING'
    return '', error_msg, flight_aware_status_code, time.time()

  last_query_time = time.time()
  last_query_flight_number = flight_number

  # https://pypi.org/project/cloudscraper/
  scraper=cloudscraper.create_scraper()
  try:
    response = scraper.get(url, timeout=5)
    query_time = time.time()
  except requests.exceptions.RequestException as e:
    query_time = time.time()  # did not get to the query_time assignment above
    error_msg = 'Unable to query FA for URL due to %s: %s' % (e, url)
    flight_aware_status_code = 'FAILURE'
    return '', error_msg, flight_aware_status_code, query_time

  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)
    flight_aware_status_code = 'FAILURE'
    return '', error_msg, flight_aware_status_code, query_time




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