Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poc for avwx api fix #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13,925 changes: 0 additions & 13,925 deletions logfile.log

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions metar-display-v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#Import needed libraries
#Misc libraries
import urllib.request, urllib.error, urllib.parse
import requests
import xml.etree.ElementTree as ET
import time
import sys
Expand Down Expand Up @@ -610,8 +611,8 @@ def set_data():
#depending on what data is to be displayed, either use an URL for METARs and TAFs or read file from drive (pass).
if metar_taf_mos == 1: #Check to see if the script should display TAF data (0) or METAR data (1)
#Define URL to get weather METARS. If no METAR reported withing the last 2.5 hours, Airport LED will be white (nowx).
url = "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&mostRecentForEachStation=constraint&hoursBeforeNow="+str(metar_age)+"&stationString="
logger.info("METAR Data Loading")
url = f"https://aviationweather.gov/api/data/metar?hours={metar_age}&ids={apts}"
logger.info(f"METAR Data Loading from url: {url}")

elif metar_taf_mos == 0: #TAF data
#Define URL to get weather URL for TAF. If no TAF reported for an airport, the Airport LED will be white (nowx).
Expand All @@ -637,7 +638,7 @@ def set_data():

while True: #check internet availability and retry if necessary. Power outage, map may boot quicker than router.
try:
content = urllib.request.urlopen(url)
ret = requests.get(url, headers={'Accept': 'application/xml'})
logger.info('Internet Available')
logger.info(url)
break
Expand All @@ -647,7 +648,10 @@ def set_data():
time.sleep(delay_time)
pass

root = ET.fromstring(content.read()) #Process XML data returned from FAA
try:
root = ET.fromstring(ret.text) #Process XML data returned from FAA
except xml.etree.ElementTree.ParseError as ex:
logger.info(f"failed to parse XML, text: {ret.text}")

#MOS decode routine
#MOS data is downloaded daily from; https://www.weather.gov/mdl/mos_gfsmos_mav to the local drive by crontab scheduling.
Expand Down Expand Up @@ -1063,7 +1067,7 @@ def set_data():
windgustkt = int(metar.find('wind_gust_kt').text)

#grab wind direction from returned FAA data
if metar.find('wind_dir_degrees') is None: #if wind speed is blank, then bypass
if metar.find('wind_dir_degrees') is None or metar.find('wind_dir_degrees').text == 'VRB': #if wind speed is blank, then bypass
winddirdegree = 0
else:
winddirdegree = int(metar.find('wind_dir_degrees').text)
Expand Down
Loading