-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws.py
33 lines (30 loc) · 1.23 KB
/
ws.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
31
32
33
import os
from requests import request
API_KEY = os.environ.get("API_KEY")
def get_weather(query=''):
if not query:
query = 'fetch:ip'
response = request(
method='GET',\
url='http://api.weatherstack.com/current',
params={
'access_key': API_KEY,
'query': query
}
)
if response.status_code == 200:
return {
'icon': response.json()['current']['weather_icons'][0],
'temperature': response.json()['current']['temperature'],
'feelslike': response.json()['current']['feelslike'],
'wind_speed': response.json()['current']['wind_speed'],
'wind_degree': response.json()['current']['wind_degree'],
'wind_dir': response.json()['current']['wind_dir'],
'cloudcover': response.json()['current']['cloudcover'],
'pressure': response.json()['current']['pressure'],
'precip': response.json()['current']['precip'],
'humidity': response.json()['current']['humidity'],
'visibility': response.json()['current']['visibility'],
'query_name': response.json()['request']['query'],
'query_type': response.json()['request']['type']
}