Private
Public Access
1
0

better metar

This commit is contained in:
Sander Roosendaal
2019-05-04 21:46:57 +02:00
parent 2f85e1ed29
commit a1c90245cd

View File

@@ -50,7 +50,6 @@ def get_metar_data(airportcode,unixtime):
url += str(unixtime+3600)
url += "&stationString="+airportcode
try:
s = requests.get(url)
except:
@@ -60,13 +59,16 @@ def get_metar_data(airportcode,unixtime):
if s.ok:
doc = etree.fromstring(s.content)
lengte = len(doc.xpath('data/METAR/station_id'))
print('Lengte ',lengte,int(lengte/2))
idnr = int(lengte/2)
try:
id = doc.xpath('data/METAR/station_id')[0].text
temp_c = doc.xpath('data/METAR/temp_c')[0].text
wind_dir = doc.xpath('data/METAR/wind_dir_degrees')[0].text
wind_speed = doc.xpath('data/METAR/wind_speed_kt')[0].text
timestamp = doc.xpath('data/METAR/observation_time')[0].text
rawtext = doc.xpath('data/METAR/raw_text')[0].text
id = doc.xpath('data/METAR/station_id')[idnr].text
temp_c = doc.xpath('data/METAR/temp_c')[idnr].text
wind_dir = doc.xpath('data/METAR/wind_dir_degrees')[idnr].text
wind_speed = doc.xpath('data/METAR/wind_speed_kt')[idnr].text
timestamp = doc.xpath('data/METAR/observation_time')[idnr].text
rawtext = doc.xpath('data/METAR/raw_text')[idnr].text
except IndexError:
message = 'Failed to download METAR data'
return [0,0,message,'',timestamp]