class FarmSense(): wdb = weatherDB({}); def __init__(self, codigo): location, latitude, longitude = locationSiteCoordenate(codigo) timestp = int(time.time()) url = f"https://api.farmsense.net/v1/daylengths/?d={timestp}&lat={latitude}&lon={longitude}" result = requests.get(url) clima = result.json() main = clima[0] if main['ErrorMessage'] == '': self.wdb.setMeasure('astrodusk' ,main['Astrodusk']) self.wdb.setMeasure('dawn' ,main['Dawn']) self.wdb.setMeasure('dayLength' ,main['Daylength']) self.wdb.setMeasure('dusk' ,main['Dusk']) self.wdb.setMeasure('sunRise' ,main['Sunrise']) self.wdb.setMeasure('sunSet' ,main['Sunset']) self.wdb.setMeasure('zenith' ,main['Zenith']) url = f"https://api.farmsense.net/v1/moonphases/?d={timestp}" result = requests.get(url) clima = result.json() main = clima[0] if main['ErrorMsg'] == 'success': self.wdb.setMeasure('moonName' ,main['Moon'][0]) self.wdb.setMeasure('moonIndex' ,main['Index']) self.wdb.setMeasure('moonAge' ,main['Age']) self.wdb.setMeasure('moonPhase' ,main['Phase']) self.wdb.setMeasure('moonDistance' ,main['Distance']) self.wdb.setMeasure('moonIllumination' ,main['Illumination']) self.wdb.setMeasure('moonAngularDiameter',main['AngularDiameter']) self.wdb.setMeasure('moonDistanceToSun' ,main['DistanceToSun']) self.wdb.setMeasure('sunAngularDiameter' ,main['SunAngularDiameter']) self.wdb.setMeasureClean()
class DarkSky(): wdb = weatherDB({}) def __init__(self, apiKey, codigo): site, self.latitude, self.longitude = locationSiteCoordenate(codigo) if self.latitude != 0 and self.longitude != 0: fcast = forecast(apiKey, self.latitude, self.longitude, units='si') else: fcast = [] if (fcast): main = fcast.currently self.wdb.setMeasure('humidity' ,main.humidity * 100) self.wdb.setMeasure('pressure' ,main.pressure) self.wdb.setMeasure('temperature' ,main.temperature) self.wdb.setMeasure('temperatureApparent',main.apparentTemperature) self.wdb.setMeasure('temperatureDew' ,main.dewPoint) self.wdb.setMeasure('weatherMain' ,main.summary) self.wdb.setMeasure('latitude' ,self.latitude ) self.wdb.setMeasure('longitude' ,self.longitude) self.wdb.setMeasure('windSpeed' ,main.windSpeed * 3.6) self.wdb.setMeasure('windGust' ,main.windGust * 3.6) self.wdb.setMeasure('windDegrees' ,main.windBearing ) self.wdb.setMeasure('rainIntensity' ,main.precipIntensity) self.wdb.setMeasure('rainProbability' ,main.precipProbability * 100) self.wdb.setMeasure('skyUVIndex' ,main.uvIndex) self.wdb.setMeasure('skyClouds' ,main.cloudCover * 100) self.wdb.setMeasure('skyOzone' ,main.ozone) self.wdb.setMeasure('skyVisibility' ,main.visibility ) self.wdb.setMeasureClean()
def info_main(self): # Calendar & Host info horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") hostName = socket.gethostname() hostIP = socket.gethostbyname("Info") # Inside Home Weather Info wdb = weatherDB({}) wdb.getCollectData('Home CLV', 'RBPI Weather Station') tempInt = wdb.getMeasure('temperature') humInt = wdb.getMeasure('humidity') dataWeather = { "tempInt": tempInt, "humInt": humInt, "time": horario, "mes": calMes, "dia": calDay, "sem": calWek } return json.dumps(dataWeather)
def display_main(self): # Calendar & Host info horario = time.strftime ("%H:%M") calMes = time.strftime ("%b") calWek = time.strftime ("%a"); calDay = time.strftime ("%d"); Tempo = "{a} {b} {c} {d}".format(a=horario, b=calMes, c=calWek, d=calDay) hostName = socket.gethostname() hostIP = socket.gethostbyname ("rbpidisplay") # Inside Home Weather Info wdb = weatherDB ({}) wdb.getCollectData ('Home GYN', 'RBPI Weather Station') tempLab = wdb.getMeasure('temperature') humLab = wdb.getMeasure('humidity') wdb.getCollectData (self.cidade, 'darksky.net') dadosDSK = wdb.getData() dadosDSK.sort() wdb.getCollectData (self.cidade, 'openweathermap.org') dadosOWM = wdb.getData() dadosOWM.sort() wdb.getCollectData (self.cidade, 'yr.no') dadosYR = wdb.getData() dadosYR.sort() Temp = 0 Hum = 0 for code,medida,unidade,valor in dadosDSK: if medida == 'temperature': Temp += valor; if medida == 'humidity': Hum += valor; for code,medida,unidade,valor in dadosOWM: if medida == 'temperature': Temp += valor; if medida == 'humidity': Hum += valor; for code,medida,unidade,valor in dadosYR: if medida == 'temperature': Temp += valor; Temp /= 3.0 Hum /= 2.0 # DEFAULT FRONT END DISPLAY # TEMPLATE display_main.html template = 'main/' + inspect.currentframe().f_code.co_name + ".html" return render_template (template, infoDSK = dadosDSK, infoOWM = dadosOWM, infoYR = dadosYR, IATA = self.IATA, TEMPO = Tempo, TEMP = Temp, HUM = Hum, TEMPLAB = tempLab, HUMLAB = humLab)
def info_weather(self): horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") # Inside Home Weather Info wdb = weatherDB({}) wdb.getCollectData('Home CLV', 'RBPI Weather Station') tempInt = wdb.getMeasure('temperature') humInt = wdb.getMeasure('humidity') # Weather Info tempExtList = [] humExtList = [] weatherDesc = [] wdb.getCollectData('CLV', 'darksky.net') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherMain') != 0: weatherDesc.append(wdb.getMeasure('weatherMain')) wdb.getCollectData('CLV', 'openweathermap.org') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherDesc') != 0: weatherDesc.append(wdb.getMeasure('weatherDesc')) wdb.getCollectData('CLV', 'yr.no') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherMain') != 0: weatherDesc.append(wdb.getMeasure('weatherMain')) humExt = reduce(lambda x, y: x + y, humExtList) / 3.0 tempExt = reduce(lambda x, y: x + y, tempExtList) / 3.0 moon = "cheia" dataWeather = { "time": horario, "mes": calMes, "dia": calDay, "sem": calWek, "temp": tempInt, "hum": humInt, "tempExt": tempExt, "humExt": humExt, "description": weatherDesc, "moon": moon } return json.dumps(dataWeather)
def display_weather(self): horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") # Inside Home Weather Info wdb = weatherDB({}) wdb.getCollectData('Home GYN', 'RBPI Weather Station') tempInt = wdb.getMeasure('temperature') humInt = wdb.getMeasure('humidity') # Weather Info tempExtList = [] humExtList = [] weatherDesc = [] wdb.getCollectData('GYN', 'darksky.net') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherMain') != 0: weatherDesc.append(wdb.getMeasure('weatherMain')) wdb.getCollectData('GYN', 'openweathermap.org') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherDesc') != 0: weatherDesc.append(wdb.getMeasure('weatherDesc')) wdb.getCollectData('GYN', 'yr.no') tempExtList.append(wdb.getMeasure('temperature')) humExtList.append(wdb.getMeasure('humidity')) if wdb.getMeasure('weatherMain') != 0: weatherDesc.append(wdb.getMeasure('weatherMain')) weatherImgList = self.getImgWeather(weatherDesc) humExt = reduce(lambda x, y: x + y, humExtList) / 3.0 tempExt = reduce(lambda x, y: x + y, tempExtList) / 3.0 moon = "cheia" template = 'weather/' + inspect.currentframe().f_code.co_name + ".html" return render_template(template, time=horario, mes=calMes, dia=calDay, sem=calWek, temp=tempInt, hum=humInt, tempApa=tempExt, humApa=humExt, images=weatherImgList, moon=moon)
class YR(): wdb = weatherDB({}) def __init__(self, codigo): site = locationSite(codigo) weather = Yr(site) main = weather.now() if (main): self.wdb.setMeasure('pressure' , main['pressure'] ['@value'] ) self.wdb.setMeasure('temperature' , main['temperature'] ['@value'] ) self.wdb.setMeasure('weatherMain' , main['symbol'] ['@name'] ) self.wdb.setMeasure('windSpeed' , float(main['windSpeed'] ['@mps']) * 3.6) self.wdb.setMeasure('windMain' , main['windSpeed'] ['@name'] ) self.wdb.setMeasure('windDegrees' , main['windDirection']['@deg'] ) self.wdb.setMeasure('rainProbability' , main['precipitation']['@value'] ) self.wdb.setMeasureClean()
def getWeather (self, codigo): # CURRENT SOURCES AND TRANSLATORS if self.source == 'darksky.net': self.dados = DarkSky (self.apiKey, codigo) elif self.source == 'openweathermap.org': self.dados = OpenWeatherMap(self.apiKey, codigo) elif self.source == 'yr.no': self.dados = YR(codigo) elif self.source == 'farmsense.net': self.dados = FarmSense(codigo) else: self.dados = {} # RETURN COLLECTED DATA if self.dados: self.codigo = codigo return self.dados.wdb else: self.codigo = "" return weatherDB ({})
class OpenWeatherMap(): wdb = weatherDB({}); def __init__(self, apiKey, codigo): location = locationCity(codigo) url = "https://api.openweathermap.org/data/2.5/weather?q={}&units=metric&appid={}".format(location, apiKey) result = requests.get(url) clima = result.json() weather = clima['weather'][0] main = clima['main'] clouds = clima['clouds'] cldkey = [x for x in clouds.keys()][0] cldval = clouds[cldkey] coord = clima['coord'] wind = clima['wind'] speed = 0 deg = 0 if 'speed' in wind: speed = wind['speed'] if 'deg' in wind: deg = wind['deg'] sys = clima['sys'] self.wdb.setMeasure('humidity' ,main['humidity']) self.wdb.setMeasure('pressure' ,main['pressure']) self.wdb.setMeasure('temperature' ,main['temp']) self.wdb.setMeasure('temperatureMax' ,main['temp_max']) self.wdb.setMeasure('temperatureMin' ,main['temp_min']) self.wdb.setMeasure('weatherMain' ,weather['main']) self.wdb.setMeasure('weatherDesc' ,weather['description']) self.wdb.setMeasure('latitude' ,coord['lat']) self.wdb.setMeasure('longitude' ,coord['lon']) self.wdb.setMeasure('skyClouds' ,cldval) if 'visibility' in clima: self.wdb.setMeasure('skyVisibility' ,clima['visibility'] / 1000) self.wdb.setMeasure('windSpeed' ,speed * 3.6) self.wdb.setMeasure('windDegrees' ,deg) self.wdb.setMeasure('sunrise' ,sys['sunrise']) self.wdb.setMeasure('sunset' ,sys['sunset']) self.wdb.setMeasureClean()
def display_main(self): # Calendar & Host info horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") hostName = socket.gethostname() hostIP = socket.gethostbyname("rbpidisplay") # Inside Home Weather Info wdb = weatherDB({}) wdb.getCollectData('Home GYN', 'RBPI Weather Station') tempInt = wdb.getMeasure('temperature') humInt = wdb.getMeasure('humidity') template = 'weather/' + inspect.currentframe().f_code.co_name + ".html" return render_template(template, tempInt=tempInt, humInt=humInt, time=horario, mes=calMes, dia=calDay, sem=calWek)
def display_cidade(self): cidade = self.codigo # Calendar & Host info horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") hostName = socket.gethostname() hostIP = socket.gethostbyname("rbpidisplay") # Weather Info wdb = weatherDB({}) wdb.getCollectData(cidade, 'openweathermap.org') tempExt = wdb.getMeasure('temperature') temp_max = int(wdb.getMeasure('temperatureMax')) temp_min = int(wdb.getMeasure('temperatureMin')) sunRise = datetime.datetime.fromtimestamp(wdb.getMeasure('sunrise')) sunrise = '{}'.format(sunRise.strftime("%H:%M")) sunSet = datetime.datetime.fromtimestamp(wdb.getMeasure('sunset')) sunset = '{}'.format(sunSet.strftime("%H:%M")) wdb.getCollectData(cidade, 'darksky.net') humExt = wdb.getMeasure('humidity') pressure = wdb.getMeasure('pressure') precipProbability = wdb.getMeasure('rainProbability') dewPoint = wdb.getMeasure('temperatureDew') aparentTemperature = wdb.getMeasure('temperatureApparent') weather = wdb.getMeasure('weatherMain') weather_desc = wdb.getMeasure('weatherDesc') uvIndex = wdb.getMeasure('skyUVIndex') ozone = wdb.getMeasure('skyOzone') visibility = "%.0f" % wdb.getMeasure('skyVisibility') wind_deg = wdb.getMeasure('windDegrees') direction = self.degToCompass(wind_deg) wind_speed = wdb.getMeasure('windSpeed') template = 'weather/' + inspect.currentframe().f_code.co_name + ".html" return render_template(template, cidade=cidade, tempMin=temp_min, tempExt=tempExt, tempMax=temp_max, weather=weather, codigo=self.codigo, time=horario, mes=calMes, dia=calDay, sem=calWek, pressure=pressure, humExt=humExt, windSpeed=wind_speed, precipProbability=precipProbability, dewPoint=dewPoint, direction=direction, uvIndex=uvIndex, ozone=ozone, visibility=visibility, aparent=aparentTemperature, sunrise=sunrise, sunset=sunset)
def info_cidade(self): cidade = self.codigo # Calendar & Host info horario = time.strftime("%H:%M") calMes = time.strftime("%b") calWek = time.strftime("%a") calDay = time.strftime("%d") hostName = socket.gethostname() hostIP = socket.gethostbyname("Info") # Weather Info wdb = weatherDB({}) wdb.getCollectData(cidade, 'openweathermap.org') tempExt = wdb.getMeasure('temperature') temp_max = int(wdb.getMeasure('temperatureMax')) temp_min = int(wdb.getMeasure('temperatureMin')) sunRise = datetime.datetime.fromtimestamp(wdb.getMeasure('sunrise')) sunrise = '{}'.format(sunRise.strftime("%H:%M")) sunSet = datetime.datetime.fromtimestamp(wdb.getMeasure('sunset')) sunset = '{}'.format(sunSet.strftime("%H:%M")) wdb.getCollectData(cidade, 'darksky.net') humExt = wdb.getMeasure('humidity') pressure = wdb.getMeasure('pressure') precipProbability = wdb.getMeasure('rainProbability') dewPoint = wdb.getMeasure('temperatureDew') aparentTemperature = wdb.getMeasure('temperatureApparent') weather = wdb.getMeasure('weatherMain') weather_desc = wdb.getMeasure('weatherDesc') uvIndex = wdb.getMeasure('skyUVIndex') ozone = wdb.getMeasure('skyOzone') visibility = "%.0f" % wdb.getMeasure('skyVisibility') wind_deg = wdb.getMeasure('windDegrees') direction = self.degToCompass(wind_deg) wind_speed = wdb.getMeasure('windSpeed') dataWeather = { "cidade": cidade, "tempMin": temp_min, "tempExt": tempExt, "tempMax": temp_max, "weather": weather, "codigo": self.codigo, "time": horario, "mes": calMes, "dia": calDay, "sem": calWek, "pressure": pressure, "humExt": humExt, "windSpeed": wind_speed, "precipProbability": precipProbability, "dewPoint": dewPoint, "direction": direction, "uvIndex": uvIndex, "ozone": ozone, "visibility": visibility, "aparent": aparentTemperature, "sunrise": sunrise, "sunset": sunset } return json.dumps(dataWeather)