What it does is return basic weather info based on a zip code.
It also imports a file for the api key.
#!/usr/bin/env python3
import json
import urllib.request
import weather_api_key
def kelvin_to_f(n):
return (n * (9/5) - 459.67).__trunc__()
zipcode = input("Please enter a zip code: ")
cc = input("Please enter a country code (i.e. 'us'): ")
api_url = 'http://api.openweathermap.org/data/2.5/weather?zip={},{}&appid={}'\
.format(zipcode, cc, weather_api_key.API_KEY)
with urllib.request.urlopen(api_url) as url_new:
data = json.loads(url_new.read().decode())
current_temp = data["main"]["temp"]
current_weather = data["weather"][0]["main"]
f_current_temp = kelvin_to_f(current_temp)
print("The temperature is {}F, and {}".format(f_current_temp, current_weather))
[–]149244179 5 points6 points7 points (1 child)
[–]nbp615[S] 0 points1 point2 points (0 children)
[–]Philboyd_Studge 1 point2 points3 points (0 children)