Skip to content

Instantly share code, notes, and snippets.

@sovietspy2
Created August 18, 2018 14:03
Show Gist options
  • Save sovietspy2/93877f7dac9d716582fbb44bf6eb26b8 to your computer and use it in GitHub Desktop.
Save sovietspy2/93877f7dac9d716582fbb44bf6eb26b8 to your computer and use it in GitHub Desktop.
Python3 global weather forecast example
#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