Skip to content

Commit

Permalink
Fixed FAA API
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Nov 9, 2023
1 parent 769a127 commit 7617844
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion data.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kflg
kdal
-2
0
0
16 changes: 8 additions & 8 deletions metar_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions metar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -219,5 +220,4 @@ def main():
print("Done")
time.sleep(60) # Sets interval of updates. 60 = 1 minute
epd.init()
epd.sleep()

epd.sleep() """
4 changes: 3 additions & 1 deletion metar_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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']
Expand Down

0 comments on commit 7617844

Please sign in to comment.