mORE
This commit is contained in:
parent
4024fe20ad
commit
34247058f3
33
weather.py
33
weather.py
|
@ -1,4 +1,5 @@
|
||||||
import requests,argparse
|
import requests,argparse, yaml
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Weather Finder")
|
parser = argparse.ArgumentParser(description="Weather Finder")
|
||||||
parser.add_argument('ZIP', metavar='ZIP', type=str, action='store',
|
parser.add_argument('ZIP', metavar='ZIP', type=str, action='store',
|
||||||
|
@ -15,21 +16,25 @@ def ktof(kelvin):
|
||||||
class output:
|
class output:
|
||||||
pass
|
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")
|
def main():
|
||||||
data = response.json()
|
args = parser.parse_args(namespace=output)
|
||||||
|
zip = output.ZIP
|
||||||
|
|
||||||
lon = str(data['lon'])
|
response = requests.get(url = "http://api.openweathermap.org/geo/1.0/zip?zip=" + zip + ",US&appid=470cdb622a085c754b7cad56ec455072")
|
||||||
lat = str(data['lat'])
|
data = response.json()
|
||||||
|
|
||||||
response2 = requests.get(url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=470cdb622a085c754b7cad56ec455072")
|
lon = str(data['lon'])
|
||||||
data2 = response2.json()
|
lat = str(data['lat'])
|
||||||
|
|
||||||
current_temp = str(ktof(data2['main']['temp']))
|
response2 = requests.get(url = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&appid=470cdb622a085c754b7cad56ec455072&units=imperial")
|
||||||
max_temp = ktof(data2['main']['temp_max'])
|
data2 = response2.json()
|
||||||
min_temp = ktof(data2['main']['temp_min'])
|
|
||||||
|
|
||||||
print(current_temp + "*F")
|
current_temp = str(data2['main']['temp'])
|
||||||
print(data2['weather'])
|
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()
|
Loading…
Reference in a new issue