From 7617844245bcc0ec3065218d67469d2a3e8ca563 Mon Sep 17 00:00:00 2001 From: markyharris Date: Thu, 9 Nov 2023 16:03:11 -0700 Subject: [PATCH] Fixed FAA API --- data.txt | 2 +- metar_layouts.py | 16 ++++++++-------- metar_main.py | 8 ++++---- metar_routines.py | 4 +++- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/data.txt b/data.txt index 6903526..5cd238f 100644 --- a/data.txt +++ b/data.txt @@ -1,4 +1,4 @@ -kflg +kdal -2 0 0 diff --git a/metar_layouts.py b/metar_layouts.py index 58ddbba..5ce3871 100755 --- a/metar_layouts.py +++ b/metar_layouts.py @@ -440,11 +440,11 @@ def layout1(display, metar, remarks, print_table, use_remarks): ccheight = metar.data["properties"]["cloudLayers"][i]["base"]["value"] cctype = metar.data["properties"]["cloudLayers"][i]["amount"] - if ccheight == None: + if ccheight is None: ccheight = "" else: ccheight = '{0:.0f}'.format(ccheight * 3.28084)+" ft" - if cctype == None: + if cctype is None: cctype == "n/a" display.draw_black.text((COL1, LINE6+27+(27*i)), cctype+" "+ccheight, fill=0, font=font24b) @@ -735,11 +735,11 @@ def layout2(display,metar, remarks, print_table, use_remarks): ccheight = metar.data["properties"]["cloudLayers"][i]["base"]["value"] cctype = metar.data["properties"]["cloudLayers"][i]["amount"] - if ccheight == None: + if ccheight is None: ccheight = "" else: ccheight = '{0:.0f}'.format(ccheight * 3.28084)+" ft" - if cctype == None: + if cctype is None: cctype == "n/a" display.draw_black.text((COL1, LINE6+27+(27*i)), cctype+" "+ccheight, fill=0, font=font24b) @@ -1087,11 +1087,11 @@ def layout4(display, metar, remarks, print_table, use_remarks): ccheight = metar.data["properties"]["cloudLayers"][i]["base"]["value"] cctype = metar.data["properties"]["cloudLayers"][i]["amount"] - if ccheight == None: + if ccheight is None: ccheight = "" else: ccheight = '{0:.0f}'.format(ccheight * 3.28084)+" ft" - if cctype == None: + if cctype is None: cctype == "n/a" display.draw_black.text((COL0+5, LINE8+20), cctype+" "+ccheight, fill=255, font=font24b) @@ -1633,11 +1633,11 @@ def center_text(text, font, x_pos, y_pos): ccheight = metar.data["properties"]["cloudLayers"][i]["base"]["value"] cctype = metar.data["properties"]["cloudLayers"][i]["amount"] - if ccheight == None: + if ccheight is None: ccheight = "" else: ccheight = '{0:.0f}'.format(ccheight * 3.28084)+"ft" - if cctype == None: + if cctype is None: cctype == "n/a" x_pos, y_pos = center_text(cctype, font24b, OUTER_CIRCLES[7][0], OUTER_CIRCLES[7][1]-10) diff --git a/metar_main.py b/metar_main.py index aa820fa..e0a42cb 100755 --- a/metar_main.py +++ b/metar_main.py @@ -121,7 +121,8 @@ def main(): epd = epd7in5b_V2.EPD() # Instantiate instance for display. while True: - try: +# try: + while True: # debug # error = 1/0 #debug # forces error to test the try-except statements # if True: # used instead of the try-except statements for debug purposes. current_time = time.strftime("%m/%d/%Y %H:%M", time.localtime()) @@ -179,7 +180,7 @@ def main(): epd.init() epd.sleep() - except Exception as e: + """ except Exception as e: time.sleep(2) print("Error Occurred in Main While Loop") exception_type, exception_object, exception_traceback = sys.exc_info() @@ -219,5 +220,4 @@ def main(): print("Done") time.sleep(60) # Sets interval of updates. 60 = 1 minute epd.init() - epd.sleep() - + epd.sleep() """ diff --git a/metar_routines.py b/metar_routines.py index aa7a0fb..adddcd6 100755 --- a/metar_routines.py +++ b/metar_routines.py @@ -46,7 +46,8 @@ def get_ip_address(): # Get Flight Categories for Class B and Class C airports def get_flightcat(): # api url - url = "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&mostRecentForEachStation=constraint&hoursBeforeNow=2.5&stationString=" +# url = "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&mostRecentForEachStation=constraint&hoursBeforeNow=2.5&stationString=" + url = "https://aviationweather-cprk.ncep.noaa.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&mostRecentForEachStation=constraint&hoursBeforeNow=2.5&stationString=" fc_dict = {} vfr_dict = {} @@ -61,6 +62,7 @@ def get_flightcat(): url = url+ap+"," content = urllib.request.urlopen(url).read() + root = ET.fromstring(content) #Process XML data returned from FAA for data in root.iter('data'): num_results = data.attrib['num_results']