Minor pushes of old updates
-Minor Linux fixes for /tmp, -remove seperate discord messages, all one -Fix empty discord roles
This commit is contained in:
parent
1f99e82f5f
commit
f600964f93
14
__main__.py
14
__main__.py
|
@ -4,13 +4,19 @@ import time
|
|||
from colorama import Fore, Back, Style
|
||||
import platform
|
||||
import traceback
|
||||
import os
|
||||
if platform.system() == "Windows":
|
||||
from colorama import init
|
||||
init(convert=True)
|
||||
elif platform.system() == "Linux":
|
||||
if os.path.exists("/tmp/plane-notify"):
|
||||
import shutil
|
||||
shutil.rmtree("/tmp/plane-notify")
|
||||
os.makedirs("/tmp/plane-notify")
|
||||
os.makedirs("/tmp/plane-notify/chrome")
|
||||
from planeClass import Plane
|
||||
from datetime import datetime
|
||||
import pytz
|
||||
import os
|
||||
import signal
|
||||
abspath = os.path.abspath(__file__)
|
||||
dname = os.path.dirname(abspath)
|
||||
|
@ -49,11 +55,13 @@ main_config.read('./configs/mainconf.ini')
|
|||
source = main_config.get('DATA', 'SOURCE')
|
||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||
from defDiscord import sendDis
|
||||
role_id = main_config.get('DISCORD', 'ROLE_ID') if main_config.has_option('DISCORD', 'ROLE_ID') and main_config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis("Started", main_config, role_id = main_config.get('DISCORD', 'ROLE_ID'))
|
||||
def service_exit(signum, frame):
|
||||
if main_config.getboolean('DISCORD', 'ENABLE'):
|
||||
from defDiscord import sendDis
|
||||
sendDis("Service Stop", main_config, role_id = main_config.get('DISCORD', 'ROLE_ID'))
|
||||
role_id = main_config.get('DISCORD', 'ROLE_ID') if main_config.has_option('DISCORD', 'ROLE_ID') and main_config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis("Service Stop", main_config, role_id = role_id)
|
||||
raise SystemExit("Service Stop")
|
||||
signal.signal(signal.SIGTERM, service_exit)
|
||||
if os.path.isfile("lookup_route.py"):
|
||||
|
@ -69,7 +77,7 @@ try:
|
|||
print("Found the following configs")
|
||||
for dirpath, dirname, filename in os.walk("./configs"):
|
||||
for filename in [f for f in filename if f.endswith(".ini") and f != "mainconf.ini"]:
|
||||
if not "disabled" in dirpath:
|
||||
if "disabled" not in dirpath:
|
||||
print(os.path.join(dirpath, filename))
|
||||
plane_config = configparser.ConfigParser()
|
||||
plane_config.read((os.path.join(dirpath, filename)))
|
||||
|
|
|
@ -30,6 +30,7 @@ def getClosestAirport(latitude, longitude, allowed_types):
|
|||
return closest_airport_dict
|
||||
def get_airport_by_icao(icao):
|
||||
with open('./dependencies/airports.csv', 'r', encoding='utf-8') as airport_csv:
|
||||
matching_airport = None
|
||||
airport_csv_reader = csv.DictReader(filter(lambda row: row[0]!='#', airport_csv))
|
||||
for airport in airport_csv_reader:
|
||||
if airport['gps_code'] == icao:
|
||||
|
@ -37,5 +38,8 @@ def get_airport_by_icao(icao):
|
|||
#Convert indent key to icao key as its labeled icao in other places not ident
|
||||
matching_airport['icao'] = matching_airport.pop('gps_code')
|
||||
break
|
||||
matching_airport = add_airport_region(matching_airport)
|
||||
return matching_airport
|
||||
if matching_airport:
|
||||
matching_airport = add_airport_region(matching_airport)
|
||||
return matching_airport
|
||||
else:
|
||||
return None
|
10
defSS.py
10
defSS.py
|
@ -8,14 +8,17 @@ from selenium.webdriver.common.by import By
|
|||
from selenium.common.exceptions import NoSuchElementException
|
||||
|
||||
def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_track_labels=False, overrides={}):
|
||||
import os
|
||||
import platform
|
||||
chrome_options = webdriver.ChromeOptions()
|
||||
chrome_options.headless = True
|
||||
chrome_options.add_argument('window-size=800,800')
|
||||
chrome_options.add_argument('ignore-certificate-errors')
|
||||
#Plane images issue loading when in headless setting agent fixes.
|
||||
if platform.system() == "Linux":
|
||||
chrome_options.add_argument('crash-dumps-dir=/tmp/plane-notify/chrome')
|
||||
|
||||
#Plane images issue loading when in headless setting agent fixes.
|
||||
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.54 Safari/537.36")
|
||||
import os
|
||||
import platform
|
||||
if platform.system() == "Linux" and os.geteuid()==0:
|
||||
chrome_options.add_argument('--no-sandbox') # required when running as root user. otherwise you would get no sandbox errors.
|
||||
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
|
||||
|
@ -107,6 +110,7 @@ def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_trac
|
|||
browser.execute_script(f"arguments[0].innerText = '* {overrides['ownop']}'", element)
|
||||
time.sleep(5)
|
||||
browser.save_screenshot(file_path)
|
||||
browser.quit()
|
||||
def generate_adsbx_screenshot_time_params(timestamp):
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
|
|
@ -14,12 +14,11 @@ def get_avg_fuel_price():
|
|||
except Exception as e:
|
||||
print(e)
|
||||
return None
|
||||
|
||||
|
||||
def fuel_calculation(aircraft_icao_type, minutes):
|
||||
"""Calculates fuel usage, price, c02 output of a flight depending on aircraft type and flight length"""
|
||||
with open("aircraft_type_fuel_consumption_rates.json", "r") as f:
|
||||
fuellist = json.loads(f.read())
|
||||
#avg_fuel_price_per_gallon = 5.08
|
||||
fuel_flight_info = {}
|
||||
if aircraft_icao_type in fuellist.keys():
|
||||
avg_fuel_price_per_gallon = get_avg_fuel_price()
|
||||
|
@ -31,7 +30,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_lbs"] = round(fuel_used_kg * 2.20462)
|
||||
fuel_flight_info["fuel_used_lbs"] = round(fuel_used_kg * 2.20462)
|
||||
fuel_flight_info["c02_tons"] = round(c02_tons) if c02_tons > 1 else round(c02_tons, 4)
|
||||
print ("Fuel info", fuel_flight_info)
|
||||
return fuel_flight_info
|
||||
|
@ -43,10 +42,8 @@ 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'])
|
||||
lbs = "{:, }".format(fuel_info['fuel_used_lbs'])
|
||||
lbs = "{:,}".format(fuel_info['fuel_used_lbs'])
|
||||
kgs = "{:,}".format(fuel_info['fuel_used_kg'])
|
||||
fuel_message = f"\n~ {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("GLF6", 548.1)
|
||||
#fuel_message(fuel_info)
|
||||
|
|
|
@ -55,6 +55,7 @@ class Plane:
|
|||
self.track = None
|
||||
self.last_track = None
|
||||
self.circle_history = None
|
||||
self.nearest_from_airport = None
|
||||
if self.config.has_option('DATA', 'DATA_LOSS_MINS'):
|
||||
self.data_loss_mins = self.config.getint('DATA', 'DATA_LOSS_MINS')
|
||||
else:
|
||||
|
@ -222,8 +223,11 @@ class Plane:
|
|||
def route_format(extra_route_info, type):
|
||||
from defAirport import get_airport_by_icao
|
||||
to_airport = get_airport_by_icao(self.known_to_airport)
|
||||
code = to_airport['iata_code'] if to_airport['iata_code'] != "" else to_airport['icao']
|
||||
airport_text = f"{code}, {to_airport['name']}"
|
||||
if to_airport:
|
||||
code = to_airport['iata_code'] if to_airport['iata_code'] != "" else to_airport['icao']
|
||||
airport_text = f"{code}, {to_airport['name']}"
|
||||
else:
|
||||
airport_text = f"{self.known_to_airport}"
|
||||
if 'time_to' in extra_route_info.keys() and type != "divert":
|
||||
arrival_rel = "in ~" + extra_route_info['time_to']
|
||||
else:
|
||||
|
@ -235,7 +239,10 @@ class Plane:
|
|||
header = "Now going to"
|
||||
elif type == "divert":
|
||||
header = "Now diverting to"
|
||||
area = f"{to_airport['municipality']}, {to_airport['region']}, {to_airport['iso_country']}"
|
||||
if to_airport:
|
||||
area = f"{to_airport['municipality']}, {to_airport['region']}, {to_airport['iso_country']}"
|
||||
else:
|
||||
area = ""
|
||||
route_to = f"{header} {area} ({airport_text})" + (f" arriving {arrival_rel}" if arrival_rel is not None else "")
|
||||
else:
|
||||
if type == "inital":
|
||||
|
@ -424,12 +431,8 @@ class Plane:
|
|||
elif self.landed:
|
||||
landed_time_msg = None
|
||||
landed_time = None
|
||||
if self.icao != "A835AF":
|
||||
message = (f"{type_header} {location_string}.") + ("" if route_to is None else f" {route_to}.") + ((f" {landed_time_msg}") if landed_time_msg != None else "")
|
||||
dirty_message = None
|
||||
else:
|
||||
message = (f"{type_header} {location_string}.") + ((f" {landed_time_msg}") if landed_time_msg != None else "")
|
||||
dirty_message = (f"{type_header} {location_string}.") + ("" if route_to is None else f" {route_to}.") + ((f" {landed_time_msg}") if landed_time_msg != None else "")
|
||||
|
||||
message = (f"{type_header} {location_string}.") + ("" if route_to is None else f" {route_to}.") + ((f" {landed_time_msg}") if landed_time_msg != None else "")
|
||||
print (message)
|
||||
#Google Map or tar1090 screenshot
|
||||
if Plane.main_config.get('MAP', 'OPTION') == "GOOGLESTATICMAP":
|
||||
|
@ -451,9 +454,8 @@ class Plane:
|
|||
sendTeleg(photo, message, self.config)
|
||||
#Discord
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
dis_message = f"{self.dis_title} {message}".strip() if dirty_message is None else f"{self.dis_title} {dirty_message}".strip()
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') else None
|
||||
sendDis(dis_message, self.config, role_id, self.map_file_name)
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis(message, self.config, role_id, self.map_file_name)
|
||||
#PushBullet
|
||||
if self.config.getboolean('PUSHBULLET', 'ENABLE'):
|
||||
with open(self.map_file_name, "rb") as pic:
|
||||
|
@ -477,13 +479,13 @@ class Plane:
|
|||
post_to_meta_both(self.config.get("META", "FB_PAGE_ID"), self.config.get("META", "IG_USER_ID"), self.map_file_name, message, self.config.get("META", "ACCESS_TOKEN"))
|
||||
os.remove(self.map_file_name)
|
||||
if self.landed:
|
||||
if self.known_to_airport is not None and self.nearest_from_airport is not None and self.known_to_airport != self.nearest_from_airport:
|
||||
if nearest_airport_dict is not None and self.nearest_from_airport is not None and nearest_airport_dict['icao'] != self.nearest_from_airport:
|
||||
from defAirport import get_airport_by_icao
|
||||
from geopy.distance import geodesic
|
||||
known_to_airport = get_airport_by_icao(self.known_to_airport)
|
||||
landed_airport = nearest_airport_dict
|
||||
nearest_from_airport = get_airport_by_icao(self.nearest_from_airport)
|
||||
from_coord = (nearest_from_airport['latitude_deg'], nearest_from_airport['longitude_deg'])
|
||||
to_coord = (known_to_airport['latitude_deg'], known_to_airport['longitude_deg'])
|
||||
to_coord = (landed_airport['latitude_deg'], landed_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'] 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"
|
||||
|
@ -498,7 +500,7 @@ class Plane:
|
|||
fuel_message = fuel_message(fuel_info)
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
dis_message = f"{self.dis_title} {distance_message} \nFlight Fuel Info ```{fuel_message}```".strip()
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') else None
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis(dis_message, self.config, role_id)
|
||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||
try:
|
||||
|
@ -525,11 +527,10 @@ class Plane:
|
|||
#Discord
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
dis_message = f"{self.dis_title} {route_to}".strip()
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') else None
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis(dis_message, self.config, role_id)
|
||||
#Twitter
|
||||
if self.config.getboolean('TWITTER', 'ENABLE') and self.icao == 'A835AF':
|
||||
#tweet = self.tweet_api.user_timeline(count = 1)[0]
|
||||
if self.config.getboolean('TWITTER', 'ENABLE'):
|
||||
self.latest_tweet_id = self.tweet_api.update_status(status = f"{self.twitter_title} {route_to}".strip(), in_reply_to_status_id = self.latest_tweet_id).id
|
||||
|
||||
if self.circle_history is not None:
|
||||
|
@ -793,8 +794,8 @@ class Plane:
|
|||
from defTelegram import sendTeleg
|
||||
sendTeleg(photo, message, self.config)
|
||||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') else None
|
||||
if tfr_map_filename is not None:
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
if tfr_map_filename is not None:
|
||||
sendDis(message, self.config, role_id, self.map_file_name, tfr_map_filename)
|
||||
elif tfr_map_filename is None:
|
||||
sendDis(message, self.config, role_id, self.map_file_name)
|
||||
|
@ -865,7 +866,7 @@ class Plane:
|
|||
if self.config.getboolean('DISCORD', 'ENABLE'):
|
||||
from defDiscord import sendDis
|
||||
dis_message = f"{self.dis_title} {ra_message}"
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') else None
|
||||
role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None
|
||||
sendDis(dis_message, self.config, role_id, self.map_file_name)
|
||||
#if twitter
|
||||
def expire_ra_types(self):
|
||||
|
|
Loading…
Reference in New Issue