TFRs toggle, pounds fix, photo override fix

-TFRS toggle
-Pounds fix
-Photo override fix
- Airport code on image fix
-TFR above/below addition
This commit is contained in:
Jack Sweeney 2022-06-09 18:15:54 -04:00
parent 823d280965
commit d39b404f62
5 changed files with 138 additions and 124 deletions

View File

@ -40,6 +40,7 @@ URL = webhookurl
[TFRS]
URL = http://127.0.0.1:5000/detailed_all
ENABLE = False
[TWITTER]
#GLOBAL TWITTER CONSUMER KEY AND CONSUMERS SECRET ONLY NEED TO BE HERE NOW

View File

@ -80,15 +80,19 @@ def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_trac
photo_box = browser.find_element_by_id("airplanePhoto")
finally:
import requests, json
photo_list = json.loads(requests.get("https://raw.githubusercontent.com/Jxck-S/aircraft-photos/main/photo-list.json").text)
photo_list = json.loads(requests.get("https://raw.githubusercontent.com/Jxck-S/aircraft-photos/main/photo-list.json", timeout=20).text)
if reg in photo_list.keys():
browser.execute_script("arguments[0].id = 'airplanePhoto';", photo_box)
browser.execute_script("arguments[0].removeAttribute('width')", photo_box)
browser.execute_script("arguments[0].style.width = 'inherit';", photo_box)
browser.execute_script("arguments[0].style.width = '200px';", photo_box)
browser.execute_script("arguments[0].style.float = 'left';", photo_box)
browser.execute_script(f"arguments[0].src = 'https://raw.githubusercontent.com/Jxck-S/aircraft-photos/main/images/{reg}.jpg';", photo_box)
image_copy_right = browser.find_element_by_id("copyrightInfo")
browser.execute_cdp_cmd('Emulation.setScriptExecutionDisabled', {'value': True})
copy_right_children = image_copy_right.find_elements(By.XPATH, "*")
if len(copy_right_children) > 0:
browser.execute_script(f"arguments[0].innerText = 'Image © {photo_list[reg]['photographer']}'", copy_right_children[0])
else:
browser.execute_script(f"arguments[0].appendChild(document.createTextNode('Image © {photo_list[reg]['photographer']}'))", image_copy_right)
except Exception as e:
print("Error on changing photo", e)

View File

@ -31,7 +31,7 @@ def fuel_calculation(aircraft_icao_type, minutes):
fuel_flight_info['fuel_used_kg'] = round(fuel_used_kg)
fuel_flight_info["fuel_used_gal"] = round(fuel_used_gal)
fuel_flight_info['fuel_used_lters'] = round(fuel_used_gal*3.78541)
fuel_flight_info["fuel_used_pds"] = round(fuel_used_kg * 2.20462)
fuel_flight_info["fuel_used_lbs"] = round(fuel_used_kg * 2.20462)
fuel_flight_info["c02_tons"] = c02_tons
print ("Fuel info", fuel_flight_info)
return fuel_flight_info
@ -43,10 +43,10 @@ def fuel_message(fuel_info):
cost = "{:,}".format(fuel_info['fuel_price'])
gallons = "{:,}".format(fuel_info['fuel_used_gal'])
lters = "{:,}".format(fuel_info['fuel_used_lters'])
pds = "{:,}".format(fuel_info['fuel_used_pds'])
lbs = "{:, }".format(fuel_info['fuel_used_lbs'])
kgs = "{:,}".format(fuel_info['fuel_used_kg'])
fuel_message = f"~ {gallons} gallons ({lters} liters). \n~ {pds} pds ({kgs} kg) of jet fuel used. \n~ ${cost} cost of fuel. \n~ {fuel_info['c02_tons']} tons of CO2 emissions."
fuel_message = f"~ {gallons} gallons ({lters} liters). \n~ {lbs} lbs ({kgs} kg) of jet fuel used. \n~ ${cost} cost of fuel. \n~ {fuel_info['c02_tons']} tons of CO2 emissions."
print(fuel_message)
return fuel_message
#fuel_info = fuel_calculation("B738", 180)
#fuel_info = fuel_calculation("GLF6", 548.1)
#fuel_message(fuel_info)

View File

@ -44,8 +44,13 @@ def append_airport(filename, airport, text_credit=None):
draw.text((x, y), text, fill=white, font=head_font)
#ICAO | IATA
(x, y) = (330, 765)
text = iata + " / " + icao
draw.text((x, y), text, fill=black, font=font)
if airport['iata_code'] != '' and airport['icao'] != '':
airport_codes = airport['iata_code'] + " / " + airport['icao']
elif airport['icao'] != '':
airport_codes = airport['icao']
else:
airport_codes = airport['ident']
draw.text((x, y), airport_codes, fill=black, font=font)
#Distance
(x, y) = (460, 765)
text = str(round(distance_mi, 2)) + "mi / " + str(round(distance_km, 2)) + "km away"

View File

@ -485,7 +485,7 @@ class Plane:
to_coord = (known_to_airport['latitude_deg'], known_to_airport['longitude_deg'])
distance_mi = float(geodesic(from_coord, to_coord).mi)
distance_nm = distance_mi / 1.150779448
distance_message = f"{'{:,}'.format(round(distance_mi))} mile ({'{:,}'.format(round(distance_nm))} NM) flight from {nearest_from_airport['iata_code']} to {nearest_airport_dict['iata_code']}\n"
distance_message = f"{'{:,}'.format(round(distance_mi))} mile ({'{:,}'.format(round(distance_nm))} NM) flight from {nearest_from_airport['iata_code'] if nearest_from_airport['iata_code'] != '' else nearest_from_airport['ident']} to {nearest_airport_dict['iata_code'] if nearest_airport_dict['iata_code'] != '' else nearest_airport_dict['ident']}\n"
else:
distance_message = ""
if landed_time is not None and self.type is not None:
@ -644,11 +644,12 @@ class Plane:
from shapely.geometry.polygon import Polygon
from shapely.geometry import Point
import requests, json
closest_tfr = None
in_tfr = None
if Plane.main_config.getboolean("TFRS", "ENABLE"):
tfr_url = Plane.main_config.get("TFRS", "URL")
response = requests.get(tfr_url, timeout=30)
tfrs = json.loads(response.text)
closest_tfr = None
in_tfr = None
for tfr in tfrs:
if in_tfr is not None:
break
@ -705,10 +706,12 @@ class Plane:
print("In TFR based off location checking alt next", in_tfr)
break
if not (self.alt_ft >= valDistVerLower and self.alt_ft <= valDistVerUpper):
print("But not in alt of TFR")
closest_tfr = in_tfr
closest_tfr['distance'] = 0
in_tfr = None
if self.alt_ft > valDistVerUpper:
in_tfr['context'] = "above"
elif self.alt_ft < valDistVerLower:
in_tfr['context'] = "below"
print("But not in alt of TFR", in_tfr['context'])
if in_tfr is None:
print("Closest TFR", closest_tfr)
#Generate Map
@ -773,12 +776,13 @@ class Plane:
message = f"Circling {round(nearest_airport_dict['distance_mi'], 2)}mi {cardinal} of {nearest_airport_dict['icao']}, {nearest_airport_dict['name']} at {self.alt_ft}ft. "
tfr_map_filename = None
if in_tfr is not None:
message += f" Inside TFR {in_tfr['info']['NOTAM']}, a TFR for {in_tfr['info']['Type'].title()}"
context = "Inside" if 'context' not in in_tfr.keys() else "Above" if in_tfr['context'] == 'above' else "Below"
message += f" {context} TFR {in_tfr['info']['NOTAM']}, a TFR for {in_tfr['info']['Type'].title()}"
tfr_map_filename = tfr_image(context, (self.latitude, self.longitude))
elif in_tfr is None and "distance" in closest_tfr.keys() and closest_tfr["distance"] <= 20:
elif in_tfr is None and closest_tfr is not None and "distance" in closest_tfr.keys() and closest_tfr["distance"] <= 20:
message += f" {closest_tfr['distance']} miles from TFR {closest_tfr['info']['NOTAM']}, a TFR for {closest_tfr['info']['Type']}"
tfr_map_filename = tfr_image(context, (self.latitude, self.longitude))
elif in_tfr is None and "distance" not in closest_tfr.keys():
elif in_tfr is None and closest_tfr is not None and "distance" not in closest_tfr.keys():
message += f" near TFR {closest_tfr['info']['NOTAM']}, a TFR for {closest_tfr['info']['Type']}"
raise Exception(message)