weather-python/weather.py

40 lines
1.1 KiB
Python

import requests,argparse, yaml
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
def main():
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()
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&units=imperial")
data2 = response2.json()
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()