# Python 3 program to access OpenWeatherMap.org (OWM) via custom API # ref.: https://pyowm.readthedocs.io/en/latest/v3/code-recipes.html # Mr. C. 8-20-2020 # ***************************************************************** # "id": 4081671, "name": "Oneonta", "state": "AL", "country": "US", # "coord": {"lon": -86.472763,"lat": 33.948151} # "id": 4830707, "name": "Ashville", "state": "AL", "country": "US", # "coord": {"lon": -86.254417, "lat": 33.83704} # ref.: OWM data at http://bulk.openweathermap.org/sample/ # ref.: city.list.json.gz (see ref. above) file: 05-Aug-2020 07:57 # ***************************************************************** # Libraries from gpiozero import LED from pyowm.owm import OWM #OpenWeatherMap Library import time owm = OWM('yourOWM API here') # OWM API Key - free after registering mgr = owm.weather_manager() observation = mgr.weather_at_place('Oneonta,AL,US') #observation has all data weather = observation.weather temp_dict_fahrenheit = weather.temperature('fahrenheit') temp_now_oneonta = temp_dict_fahrenheit['temp'] print('initial conditions at Oneonta, AL') print(weather.status) print(weather.detailed_status) print(temp_dict_fahrenheit) print(temp_dict_fahrenheit['temp']) rled = LED(25) # red led yled = LED(24) # yellow led gled = LED(23) # green led while True: if temp_now_oneonta >= 90.00: yled.off() gled.off() rled.on() print('temp high ', temp_dict_fahrenheit['temp'], ' deg. F') time.sleep(15) elif temp_now_oneonta >= 70.00 and temp_now_oneonta < 90.00: rled.off() gled.off() yled.on() print('temp medium ', temp_dict_fahrenheit['temp'], ' deg. F') time.sleep(15) elif temp_now_oneonta < 70.00: rled.off() yled.off() gled.on() print('temp low ', temp_dict_fahrenheit['temp'], ' deg. F') time.sleep(15) owm = OWM('xxxyour_owm_api_key_herexxx') # Mr. C.'s OWM API Key mgr = owm.weather_manager() observation = mgr.weather_at_place('Oneonta,AL,US') #observation has all data weather = observation.weather temp_dict_fahrenheit = weather.temperature('fahrenheit') temp_now_oneonta = temp_dict_fahrenheit['temp'] time.sleep(5) print('updated conditions at Oneonta, AL') print(weather.status) print(weather.detailed_status) print(temp_dict_fahrenheit) print(temp_dict_fahrenheit['temp']) continue