Created
August 18, 2018 14:03
-
-
Save sovietspy2/93877f7dac9d716582fbb44bf6eb26b8 to your computer and use it in GitHub Desktop.
Python3 global weather forecast example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 -m pip install pyowm | |
# | |
import pyowm | |
# I changed one character :D have fun finding it | |
api_key = "fd64c4e513be8dfaee03be4e9a04948" | |
def get_forcast_for_city(city): | |
owm = pyowm.OWM(api_key) # You MUST provide a valid API key | |
try: | |
observation = owm.weather_at_place(city) | |
except (Exception): | |
return "Couldn't get data for city named: "+city | |
w = observation.get_weather() | |
curr = w.get_temperature('celsius')['temp'] | |
min_t = w.get_temperature('celsius')['temp_min'] | |
max_t = w.get_temperature('celsius')['temp_max'] | |
return_value = "Weather status @ {}: {}. \n".format(city,w._detailed_status) | |
return_value+= "Current temperature is {} Celsius. \nDuring the day: maximum: {} C and minimum: {} C.".format(curr, max_t, min_t) | |
return return_value | |
print(get_forcast_for_city("Lisbon")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment