-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
33 lines (26 loc) · 902 Bytes
/
api.py
File metadata and controls
33 lines (26 loc) · 902 Bytes
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 requests
import json
from keys import API_KEY
# zipCode = "10001"
#
# url = "http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode={}&distance=50&API_KEY={}".format(zipCode, API_KEY)
#
# api_request = requests.get(url)
# data = json.loads(api_request.content)
# city = data[0]['ReportingArea']
# quality = data[0]['AQI']
# category = data[0]['Category']['Name']
#
# print(city, quality, category)
# print(data)
# coding: utf-8
import requests
params = {
'access_key': 'b473c6937a0660adf948dce436521ef8',
'query': 'New York'
}
api_result = requests.get('http://api.weatherstack.com/current', params)
api_response = json.loads(api_result.content)
print(api_response)
print(u'Current temperature in %s is %d℃' % (api_response['location']['name'], api_response['current']['temperature']))
print(api_response['current']['weather_descriptions'][0])