Private
Public Access
1
0

passes checks in python3

This commit is contained in:
Sander Roosendaal
2019-02-24 15:57:26 +01:00
parent c7ec31344b
commit 866566172c
51 changed files with 4037 additions and 3999 deletions

View File

@@ -1,3 +1,4 @@
from __future__ import unicode_literals, absolute_import
import requests
import json
from lxml import objectify,etree
@@ -30,9 +31,9 @@ def get_weather_data(long,lat,unixtime):
s = requests.get(url)
if s.ok:
return s.json()
return s.json()
else:
return 0
return 0
# Get Metar data
def get_metar_data(airportcode,unixtime):
@@ -78,7 +79,7 @@ def get_metar_data(airportcode,unixtime):
message = 'Summary for your location at '+timestamp+': '
message += 'Temperature '+temp_c+'C/'+temp_f+'F'
message += '. Wind: '+str(wind_ms)+' m/s ('+str(wind_knots)+' kt)'
message += '. Wind: '+str(wind_ms)+' m/s ('+str(wind_knots)+' kt)'
message +='. Wind Bearing: '+str(windbearing)+' degrees'
# message +='\n'+rawtext
@@ -93,36 +94,36 @@ def get_metar_data(airportcode,unixtime):
def get_wind_data(lat,long,unixtime):
data = get_weather_data(lat,long,unixtime)
if data:
try:
# we are getting wind in mph
windspeed = data['currently']['windSpeed']*0.44704
windbearing = data['currently']['windBearing']
except KeyError:
windspeed = 0
windbearing = 0
try:
# we are getting wind in mph
windspeed = data['currently']['windSpeed']*0.44704
windbearing = data['currently']['windBearing']
except KeyError:
windspeed = 0
windbearing = 0
try:
airports = data['flags']['madis-stations']
except KeyError:
airports = ['unknown']
try:
airports = data['flags']['madis-stations']
except KeyError:
airports = ['unknown']
try:
temperature = data['currently']['temperature']
try:
temperature = data['currently']['temperature']
# Temp is given in Fahrenheit, so convert to Celsius for Europeans
temperaturec = (temperature-32.)*(5./9.)
temperaturec = int(10*temperaturec)/10.
except KeyError:
temperature = 'unknown'
temperaturec = 'unknown'
temperaturec = (temperature-32.)*(5./9.)
temperaturec = int(10*temperaturec)/10.
except KeyError:
temperature = 'unknown'
temperaturec = 'unknown'
try:
summary = data['currently']['summary']
except KeyError:
summary = 'unknown'
try:
summary = data['currently']['summary']
except KeyError:
summary = 'unknown'
else:
windspeed = 0
windbearing = 0
message = 'Not able to get weather data'
windspeed = 0
windbearing = 0
message = 'Not able to get weather data'
# apply Hellman's coefficient for neutral air above human
# inhabitated areas
@@ -135,7 +136,7 @@ def get_wind_data(lat,long,unixtime):
message += '. Temperature '+str(temperature)+'F/'+str(temperaturec)+'C'
if data:
message += '. Wind: '+str(windspeed)+' m/s. Wind Bearing: '+str(windbearing)+' degrees'
message += '. Wind: '+str(windspeed)+' m/s. Wind Bearing: '+str(windbearing)+' degrees'
return [windspeed,windbearing,message,airports,timestamp]