diff --git a/weather.py b/weather.py index d32990e..dbe7a63 100644 --- a/weather.py +++ b/weather.py @@ -1,4 +1,5 @@ -import requests,argparse +import requests,argparse, yaml + parser = argparse.ArgumentParser(description="Weather Finder") parser.add_argument('ZIP', metavar='ZIP', type=str, action='store', @@ -15,21 +16,25 @@ def ktof(kelvin): class output: pass -args = parser.parse_args(namespace=output) -zip = output.ZIP -response = requests.get(url = "http://api.openweathermap.org/geo/1.0/zip?zip=" + zip + ",US&appid=470cdb622a085c754b7cad56ec455072") -data = response.json() +def main(): + args = parser.parse_args(namespace=output) + zip = output.ZIP -lon = str(data['lon']) -lat = str(data['lat']) + response = requests.get(url = "http://api.openweathermap.org/geo/1.0/zip?zip=" + zip + ",US&appid=470cdb622a085c754b7cad56ec455072") + data = response.json() -response2 = requests.get(url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=470cdb622a085c754b7cad56ec455072") -data2 = response2.json() + lon = str(data['lon']) + lat = str(data['lat']) -current_temp = str(ktof(data2['main']['temp'])) -max_temp = ktof(data2['main']['temp_max']) -min_temp = ktof(data2['main']['temp_min']) + response2 = requests.get(url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=470cdb622a085c754b7cad56ec455072&units=imperial") + data2 = response2.json() -print(current_temp + "*F") -print(data2['weather']) \ No newline at end of file + current_temp = str(data2['main']['temp']) + max_temp = str(data2['main']['temp_max']) + min_temp = str(data2['main']['temp_min']) + + + print(yaml.dump(data2, sort_keys=True, default_flow_style=False)) + +main() \ No newline at end of file