initial script, will add country support and maybe celsius support later
This commit is contained in:
commit
4d62860bf7
2
requirements.txt
Normal file
2
requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
requests
|
||||
argparse
|
34
weather.py
Normal file
34
weather.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue