def from_service(service: Service, icao: str) -> str: """ Returns the timestamp fetched from an AVWX Service object """ metar = Metar(icao) metar.update(service("metar").fetch(icao)) return metar.data.time.repr
def test_metar_ete(self): """ Performs an end-to-end test of all METAR JSON files """ for path in glob(os.path.dirname(os.path.realpath(__file__))+'/metar/*.json'): ref = json.load(open(path)) station = Metar(path.split('/')[-1][:4]) self.assertIsNone(station.last_updated) self.assertTrue(station.update(ref['data']['raw'])) self.assertIsInstance(station.last_updated, datetime) # Clear timestamp due to parse_date limitations station.data.time = None self.assertEqual(asdict(station.data), ref['data']) self.assertEqual(asdict(station.translations), ref['translations']) self.assertEqual(station.summary, ref['summary']) self.assertEqual(station.speech, ref['speech']) self.assertEqual(asdict(station.station_info), ref['station_info'])
def test_metar_ete(self): """ Performs an end-to-end test of all METAR JSON files """ for path in glob( os.path.dirname(os.path.realpath(__file__)) + '/metar/*.json'): ref = json.load(open(path)) station = Metar(path.split('/')[-1][:4]) self.assertIsNone(station.last_updated) self.assertTrue(station.update(ref['data']['raw'])) self.assertIsInstance(station.last_updated, datetime) # Clear timestamp due to parse_date limitations station.data.time = None self.assertEqual(asdict(station.data), ref['data']) self.assertEqual(asdict(station.translations), ref['translations']) self.assertEqual(station.summary, ref['summary']) self.assertEqual(station.speech, ref['speech']) self.assertEqual(asdict(station.station_info), ref['station_info'])
def test_metar_ete(self): """ Performs an end-to-end test of all METAR JSON files """ for path in Path(__file__).parent.joinpath("metar").glob("*.json"): path = Path(path) ref = json.load(path.open()) station = Metar(path.stem) self.assertIsNone(station.last_updated) self.assertTrue(station.update(ref["data"]["raw"])) self.assertIsInstance(station.last_updated, datetime) # Clear timestamp due to parse_date limitations station.data.time = None self.assertEqual(asdict(station.data), ref["data"]) self.assertEqual(asdict(station.translations), ref["translations"]) self.assertEqual(station.summary, ref["summary"]) self.assertEqual(station.speech, ref["speech"]) self.assertEqual(asdict(station.station_info), ref["station_info"])
def suggest_airports(led_ind, wrong_ident): global led_index print(error + "%s is not a valid ICAO identifier!" % wrong_ident) possible_airports = [] letter_1_suggestions = data[wrong_ident[1].lower()] letter_2_suggestions = data[wrong_ident[2].lower()] letter_3_suggestions = data[wrong_ident[3].lower()] # find suggestions for l1 in letter_1_suggestions: for l2 in letter_2_suggestions: for l3 in letter_3_suggestions: suggestion = "k" + l1 + l2 + l3 try: m = Metar(suggestion.upper()) possible_airports.append(m) except: pass print("Are of of these your airports?") index = 0 for airport in possible_airports: print("\033[1m%i.\033[0m %s | %s in %s, %s" % (index, airport.icao, airport.station.name, airport.station.city, airport.station.state)) index += 1 suggestion = get_suggestion_index(len(possible_airports)) if suggestion == "again": pass elif suggestion == "skip": if input(warn + "Are you sure you want to skip (y/n): ") in ["", "y", "yes"]: print("Skiping LED #%s" % led_ind) led_index += 1 # increment led_index else: suggest_airports(led_ind, wrong_ident) elif suggestion != "skip": selected_ap = possible_airports[suggestion] confirm = input(warn + "Are you sure you want to assign LED %i to %s (%s) in %s, %s? (y/n): " % (led_ind, selected_ap.station.name, selected_ap.icao.upper(), selected_ap.station.city, selected_ap.station.state)) if confirm.lower() in ["", "y", "yes"]: auto_save(led_ind, selected_ap.icao.upper(), selected_ap.station) led_index += 1 else: suggest_airports(led_ind, wrong_ident)
print("[SUCCESS]: Saved airports to file.") else: print("Ok. Not saving recent configuration") while run: try: ident = input("ICAO identifier for LED #%s: " % led_index) if ident == "": print("Skipping LED #%s" % led_index) led_index += 1 else: try: m = Metar(ident.upper() ) # attempts to see if avwx recognizes ICAO code config.update({ led_index: ident.upper() }) # update dictionary with led index and uppercase identifier print('Assigning %s in %s, %s to LED #%s' % ( m.station.name, m.station.city, m.station.state, led_index, )) led_index += 1 # increment led_index except: print( '[ERROR] %s is not a valid ICAO identifier! Be sure to include county code!' % ident)
class Airport: def __init__(self, ident, index): self.idnet = ident self.index = index self.station = Station.from_icao(ident) def set_metar(self, raw_metar): self.metar = Metar(self.idnet) self.metar.update(raw_metar) def get_metar(self): return self.metar def get_led_color(self): try: flight_rules = self.metar.data.flight_rules except AttributeError as err: print(err) return (0,0,0) else: if flight_rules == 'VFR': return settings.vfr_color elif flight_rules == 'MVFR': return settings.mvfr_color elif flight_rules == 'IFR': return settings.ifr_color elif flight_rules == 'LIFR': return settings.lifr_color def get_flight_rules(self): return self.metar.data.flight_rules.lower() def is_lightning(self): if 'ltg' in self.metar.data.remarks.lower(): return True for code in self.metar.data.wx_codes: if 'ts' in code.repr.lower() or 'ltg' in self.metar.data.remarks.lower(): return True return False def get_station_info(self): return self.station def is_snowing(self): if 'rn' in self.metar.data.remarks.lower(): return True for code in self.metar.data.wx_codes: if 'rn' in code.repr.lower() or 'rn' in self.metar.data.remarks.lower(): return True def get_animation_color(self): wx = [] snow_codes = ["IC ", "PL ", "SG ", "SN ", "DS "] fog_codes = ["FG ", "FU ", "DS ", "DU ", "PO ", "SS ", "VA "] if self.is_lightning(): wx.append((255,255,255)) for f in fog_codes: for c in self.metar.data.wx_codes: if c.repr in fog_codes: wx.append((119,0,255)) break if f in self.metar.data.remarks: wx.append((119,0,255)) break for s in snow_codes: for c in self.metar.data.wx_codes: if c.repr in snow_codes: wx.append((215,215,215)) break if s in self.metar.data.remarks: wx.append((215,215,215)) break return wx
def set_metar(self, raw_metar): self.metar = Metar(self.idnet) self.metar.update(raw_metar)
for i in range(len(text) - num_cols + 1): text_to_print = text[i:i + num_cols] display.lcd_display_string(text_to_print, num_line) time.sleep(0.5) time.sleep(1) else: display.lcd_display_string(text, num_line) def center_text(string): length = len(string) l = "" for _ in range(1, length - 16): pass m = Metar('KGMU') m.update() display.lcd_display_string(' Welcome To', 1) display.lcd_display_string(' raspi-metar!', 2) time.sleep(1) display.lcd_display_string(' Created by', 1) display.lcd_display_string(' Ian Thompson', 2) display.lcd_clear() while True: display.lcd_display_string(' KGMU METAR', 1) display.lcd_display_string(m.data.flight_rules + ' Conditions', 2) time.sleep(1) long_string(display, m.data.raw, 2)