def return_forecast(coordinates, city): # Extracting our coordinates lon = coordinates['lon'] lat = coordinates['lat'] # Getting the weather forecast for our city exclude = ['current', 'minutely', 'hourly'] # Excluding data we don't want from our API request url = f'https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={exclude}&{UNITS}&appid={WEATHER_API_KEY}' result = requests.get(url) data = result.json() if not result.ok: return None return Forecast(data, city)
def __transformForecast(self, forecast, units): forecast = Forecast(forecast, units) return forecast.getString()
sys.exit(0) ############################################################################### ############################################################################### if __name__ == '__main__': shutdown = Shutdown(shutdown_func=shutdown_application) qv_temp_wardrobe = SensorValue("ID_31", "TempWardrobe", SensorValue_Data.Types.Temp, "°C") qv_humi_wardrobe = SensorValue("ID_32", "HumiWardrobe", SensorValue_Data.Types.Humi, "% rF") qv_light_wardrobe = SensorValue("ID_33", "LightWardrobe", SensorValue_Data.Types.Light, "lux") sq = SensorQueueClient_write("../../configs/weatherqueue.ini") sq.register(qv_temp_wardrobe) sq.register(qv_humi_wardrobe) sq.register(qv_light_wardrobe) lightness = Lightness(qv=qv_light_wardrobe) forecast = Forecast(central_i2c_lock) controls = { 'doors': Control(Sensor1_Pin, Actuator1_ID), 'drawer': Control(Sensor2_Pin, Actuator2_ID), 'button': Control_Button(Sensor3_Pin, Actuator3_ID) } main() # eof #
from Weather import Weather from Forecast import Forecast import schedule import time try: print('PROGRAM STARTED') f = Forecast() w = Weather() # tweets the daily forecast at 7am cst as well as the weather every 4 hours throughout the day schedule.every().day.at('05:00').do(f.get) schedule.every().day.at('07:00').do(f.tweet) schedule.every().day.at('08:00').do(w.tweet) schedule.every().day.at('14:00').do(w.tweet) schedule.every().day.at('18:00').do(w.tweet) schedule.every().day.at('22:00').do(w.tweet) while 1: schedule.run_pending() time.sleep(1) except: print('PROGRAM STOPPED')
def test_api_return_dict(self): forecast_inst = Forecast(coordinates=(38.9072, -77.0369)) self.assertIsInstance(forecast_inst.api_landing, dict)
def test_api_str(self): forecast_inst = Forecast(coordinates=(38.9072, -77.0369)) self.assertIsInstance(forecast_inst.api_url, str)