-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.py
30 lines (27 loc) · 1.01 KB
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import requests
import json
from datetime import date, timedelta
from darksky import forecast
import sys
API_KEY="58ce87e229a6183b47a82b013ead67b6"
url = 'http://photon.komoot.de/api/?q='
def weather(address,query):
#Get the latitude and longitude
resp=requests.get(url=url+address)
data=json.loads(resp.text)
latitude = data['features'][0]['geometry']['coordinates'][1]
longitude = data['features'][0]['geometry']['coordinates'][0]
answer = forecast(API_KEY,latitude,longitude)
if query=='temperature':
return int((5.0/9)*(answer['hourly']['data'][2]['temperature']-32))
elif query=='humidity':
return(answer['hourly']['data'][2]['humidity'])
else:
return(answer['hourly']['data'][2]['summary'])
if sys.argv[2] == "1":
print(str(weather(sys.argv[1],"temperature"))+" degrees C")
elif sys.argv[2] == "2":
print(str(weather(sys.argv[1],"humidity")))
else:
print(str(weather(sys.argv[1],"summary")))