passes checks in python3
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user