def refresh_station_weather(): """ Attempts to get the latest weather for all stations and categorize the reports. """ for airport in airport_render_config: print "Retrieving METAR for " + airport metar = weather.get_metar(airport) print "METAR for " + airport + " = " + metar category = weather.get_category(metar) if airport in overrides: category = overrides[airport] print "Category for " + airport + " = " + category set_airport_display(airport, category)
def update_station_categorization(airport, utc_offset): """ Updates the categorization for a single given station. Arguments: airport {string} -- The identifier of the weather station. utc_offset {int} -- The number of hours off from UTC the station is. """ try: metar = weather.get_metar(airport, logger=LOGGER) category = get_airport_category(airport, metar, utc_offset) set_airport_display(airport, category, metar=metar) except Exception as e: safe_log_warning(LOGGER, 'While attempting to get category for {}, got EX:{}'.format(airport, e))
def refresh_all_weather_stations(): """ Attempts to get the latest weather for all stations and categorize the reports. """ for airport in airport_render_config: LOGGER.log_info_message("Retrieving METAR for " + airport) metar = weather.get_metar(airport) LOGGER.log_info_message("METAR for " + airport + " = " + metar) try: category = weather.get_category( airport, metar, configuration.get_night_lights()) except: category = weather.INVALID LOGGER.log_info_message("Category for " + airport + " = " + category) set_airport_display(airport, category)
def update_all_station_categorizations(): """ Takes the latest reports (probably in cache) and then updates the categorization of the airports. """ utc_offset = datetime.utcnow() - datetime.now() LOGGER.log_info_message("Updating all airports at LOCAL={}, UTC={}".format( datetime.now(), datetime.utcnow())) for airport in airport_render_config: try: metar = weather.get_metar(airport, logger=LOGGER) category = get_airport_category(airport, metar, utc_offset) set_airport_display(airport, category, metar=metar) except Exception as e: LOGGER.log_warning_message( 'While attempting to get category for {}, got EX:{}'.format(airport, e))
def wait_for_all_airports(): """ Waits for all of the airports to have been given a chance to initialize. If an airport had an error, then that still counts. """ utc_offset = datetime.utcnow() - datetime.now() for airport in airport_render_config: try: thread_lock_object.acquire() metar = weather.get_metar(airport, logger=LOGGER) category = get_airport_category(airport, metar, utc_offset) airport_conditions[airport] = (category, False) except: airport_conditions[airport] = (weather.INVALID, False) safe_log_warning( LOGGER, "Error while initializing with airport=" + airport) finally: thread_lock_object.release() return True
# Validate that the station is in the CSV file try: data_file_icao_code = weather.get_faa_csv_identifier(station_id) except Exception as e: terminal_error( 'Unable to fetch the station {} from the CSV data file. Please check that the station is in the CSV file. Error={}' .format(station_id, e)) if data_file_icao_code is None or data_file_icao_code == '' or weather.INVALID in data_file_icao_code: terminal_error( f'Unable to fetch the station {station_id} from the CSV data file. Please check that the station is in the CSV file. Error={e}' ) # Validate that the station can have weather fetched metar = weather.get_metar(station_id, logger=LOGGER) if metar is None or weather.INVALID in metar: stations_unable_to_fetch_weather.append(station_id) safe_log_warning( LOGGER, f'Unable to fetch weather for {station_id}/{led_index}') # Validate that the station can have Sunrise/Sunset fetched day_night_info = weather.get_civil_twilight(station_id) if day_night_info is None: terminal_error( f'Unable to fetch day/night info for {station_id}/{led_index}') if len(day_night_info) != 6: terminal_error(