From 4d62860bf7c566c4ea5f913827174715bb552e12 Mon Sep 17 00:00:00 2001 From: VincentKnightTesting Date: Mon, 2 May 2022 14:08:29 -0500 Subject: [PATCH] initial script, will add country support and maybe celsius support later --- README.md | 0 requirements.txt | 2 ++ weather.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 README.md create mode 100644 requirements.txt create mode 100644 weather.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c4c3553 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests +argparse diff --git a/weather.py b/weather.py new file mode 100644 index 0000000..aede105 --- /dev/null +++ b/weather.py @@ -0,0 +1,34 @@ +import requests,argparse + +parser = argparse.ArgumentParser(description="Weather Finder") +parser.add_argument('ZIP', metavar='ZIP', type=str, action='store', + help='zip code for weather',) + +def printvars(): + for name in dir(): + myvalue = eval(name) + print(name, "is", type(name), "and is equal to ", myvalue) + +def ktof(kelvin): + return round(1.8*(kelvin-273) + 32,1) + +class output: + pass + +args = parser.parse_args(namespace=output) +zip = output.url + +response = requests.get(url = "http://api.openweathermap.org/geo/1.0/zip?zip=" + zip + ",US&appid=470cdb622a085c754b7cad56ec455072") +data = response.json() + +lon = str(data['lon']) +lat = str(data['lat']) + +response2 = requests.get(url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=470cdb622a085c754b7cad56ec455072") +data2 = response2.json() + +current_temp = ktof(data2['main']['temp']) +max_temp = ktof(data2['main']['temp_max']) +min_temp = ktof(data2['main']['temp_min']) + +print(current_temp) \ No newline at end of file