diff --git a/.gitignore b/.gitignore index fe2bcb0..f78e68a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ lookup_route.py icao_url_gen.py install.sh coul_icao_gen.py +test.py diff --git a/configs/mainconf.ini.example b/configs/mainconf.ini.example index 73ec22e..114b869 100644 --- a/configs/mainconf.ini.example +++ b/configs/mainconf.ini.example @@ -20,7 +20,7 @@ API_VERSION = 1 #ADSBX API Proxy, https://gitlab.com/jjwiseman/adsbx-api-proxy, v2 input, v1 or v2 output from proxy ENABLE_PROXY = FALSE #Full URL http://host:port -PROXY_HOST = +PROXY_HOST = #OpenSky https://opensky-network.org/apidoc/index.html #When using without your own login user and pass should be None @@ -57,3 +57,8 @@ ENABLE = False ENABLE = False CONSUMER_KEY = ck CONSUMER_SECRET = cs + +[MAP] +#Map to create from Google Static Maps or screenshot global tar1090 from globe.adsbexchange.com +#Enter GOOGLESTATICMAP or ADSBX +OPTION = ADSBX \ No newline at end of file diff --git a/configs/plane1.ini.example b/configs/plane1.ini.example index fd0051e..f98570a 100644 --- a/configs/plane1.ini.example +++ b/configs/plane1.ini.example @@ -9,6 +9,8 @@ ICAO = icaohere ; OVERRIDE_TYPELONG = ; OVERRIDE_OWNER = ; DATA_LOSS_MINS = 20 +; CONCEAL_AC_ID = True +; CONCEAL_PIA = False [MAP] #Map to create from Google Static Maps or screenshot global tar1090 from globe.adsbexchange.com diff --git a/defSS.py b/defSS.py index d01f34c..ea525b3 100644 --- a/defSS.py +++ b/defSS.py @@ -6,14 +6,21 @@ import time from selenium.webdriver.support.ui import WebDriverWait 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={}): +def blur_elements_by_id(browser, element_ids): + for element in element_ids: + try: + element = browser.find_element(By.ID, element) + browser.execute_script("arguments[0].style.filter = 'blur(7px)';", element) + except NoSuchElementException: + print("Issue finding:", element, "on page") +def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_track_labels=False, overrides={}, conceal_ac_id=False, conceal_pia=False): 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') + chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) if platform.system() == "Linux": chrome_options.add_argument('crash-dumps-dir=/tmp/plane-notify/chrome') @@ -23,7 +30,7 @@ def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_trac 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) url = f"https://globe.adsbexchange.com/?{url_params}" - print(url) + print(f"Getting Screenshot of {url}") browser.set_page_load_timeout(80) browser.get(url) WebDriverWait(browser, 40).until(lambda d: d.execute_script("return jQuery.active == 0")) @@ -33,7 +40,7 @@ def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_trac element = browser.find_element(By.ID, element) browser.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element); """, element) except: - print("issue removing", element, "from map") + print("Issue finding:", element, "on page") #Remove watermark on data try: browser.execute_script("document.getElementById('selected_infoblock').className = 'none';") @@ -50,13 +57,17 @@ def get_adsbx_screenshot(file_path, url_params, enable_labels=False, enable_trac browser.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element); """, element) except: print("Couldn't remove Google Ads") - #Remove share - # try: - # element = browser.find_element_by_xpath("//*[contains(text(), 'Copy Link')]") - # browser.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element); """, element) - # except Exception as e: - # print("Couldn't remove share button from map", e) + #Remove Copy Link + try: + element = browser.find_element(By.XPATH, "//*[@id='selected_icao']/span[2]/a") + browser.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element); """, element) + except Exception as e: + print("Couldn't remove copy link button from map", e) #browser.execute_script("toggleFollow()") + if conceal_pia or conceal_ac_id: + blur_elements_by_id(browser, ["selected_callsign", "selected_icao", "selected_squawk1"]) + if conceal_ac_id: + blur_elements_by_id(browser, ["selected_registration", "selected_country", "selected_dbFlags", "selected_ownop", "selected_typelong", "selected_icaotype", "airplanePhoto", "silhouette", "copyrightInfo"]) if enable_labels: browser.find_element(By.TAG_NAME, 'body').send_keys('l') if enable_track_labels: diff --git a/planeClass.py b/planeClass.py index 187da23..fb9f0b9 100644 --- a/planeClass.py +++ b/planeClass.py @@ -24,6 +24,14 @@ class Plane: self.overrides['typelong'] = self.config.get('DATA', 'OVERRIDE_TYPELONG') if self.config.has_option('DATA', 'OVERRIDE_OWNER'): self.overrides['ownop'] = self.config.get('DATA', 'OVERRIDE_OWNER') + if self.config.has_option('DATA', 'CONCEAL_AC_ID'): + self.conceal_ac_id = self.config.getboolean('DATA', 'CONCEAL_AC_ID') + else: + self.conceal_ac_id = False + if self.config.has_option('DATA', 'CONCEAL_PIA'): + self.conceal_pia = self.config.getboolean('DATA', 'CONCEAL_PIA') + else: + self.conceal_pia = False self.conf_file_path = config_path self.alt_ft = None self.below_desired_ft = None @@ -449,7 +457,7 @@ class Plane: elif Plane.main_config.get('MAP', 'OPTION') == "ADSBX": from defSS import get_adsbx_screenshot url_params = f"largeMode=2&hideButtons&hideSidebar&mapDim=0&zoom=10&icao={self.icao}&overlays={self.get_adsbx_map_overlays()}&limitupdates=0" - get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides) + get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides, conceal_ac_id=self.conceal_ac_id, conceal_pia=self.conceal_pia) from modify_image import append_airport text_credit = self.config.get('MAP', 'TEXT_CREDIT') if self.config.has_option('MAP', 'TEXT_CREDIT') else None append_airport(self.map_file_name, nearest_airport_dict, text_credit) @@ -567,7 +575,7 @@ class Plane: if Plane.main_config.get('MAP', 'OPTION') == "ADSBX": from defSS import get_adsbx_screenshot url_params = f"largeMode=2&hideButtons&hideSidebar&mapDim=0&zoom=10&icao={self.icao}&overlays={self.get_adsbx_map_overlays()}&limitupdates=0" - get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides) + get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides, conceal_ac_id=self.conceal_ac_id, conceal_pia=self.conceal_pia) if self.config.getboolean('DISCORD', 'ENABLE'): dis_message = (self.dis_title + " " + squawk_message) sendDis(dis_message, self.config, None, self.map_file_name) @@ -590,7 +598,7 @@ class Plane: if mode == "Approach": from defSS import get_adsbx_screenshot url_params = f"largeMode=2&hideButtons&hideSidebar&mapDim=0&zoom=10&icao={self.icao}&overlays={self.get_adsbx_map_overlays()}&limitupdates=0" - get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides) + get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides, conceal_ac_id=self.conceal_ac_id, conceal_pia=self.conceal_pia) sendDis(dis_message, self.config, None, self.map_file_name) #elif mode in ["Althold", "VNAV", "LNAV"] and self.sel_nav_alt != None: # sendDis((dis_message + ", Sel Alt. " + str(self.sel_nav_alt) + ", Current Alt. " + str(self.alt_ft)), self.config) @@ -773,7 +781,7 @@ class Plane: from defSS import get_adsbx_screenshot url_params = f"largeMode=2&hideButtons&hideSidebar&mapDim=0&zoom=10&icao={self.icao}&overlays={self.get_adsbx_map_overlays()}&limitupdates=0" - get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides) + get_adsbx_screenshot(self.map_file_name, url_params, overrides=self.overrides, conceal_ac_id=self.conceal_ac_id, conceal_pia=self.conceal_pia) if nearest_airport_dict['distance_mi'] < 3: if "touchngo" in self.circle_history.keys(): message = f"Doing touch and goes at {nearest_airport_dict['icao']}" @@ -867,7 +875,7 @@ class Plane: else: url_params += f"&icao={self.icao.lower()}&noIsolation" print(url_params) - get_adsbx_screenshot(self.map_file_name, url_params, True, True, overrides=self.overrides) + get_adsbx_screenshot(self.map_file_name, url_params, True, True, overrides=self.overrides, conceal_ac_id=self.conceal_ac_id, conceal_pia=self.conceal_pia) if self.config.getboolean('DISCORD', 'ENABLE'): from defDiscord import sendDis