-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_lec1.py
More file actions
28 lines (18 loc) · 812 Bytes
/
api_lec1.py
File metadata and controls
28 lines (18 loc) · 812 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
#read api from the www.weatherbit.io and print the tempreature from the API
import requests
import json
def get_current_temperature(city,postal_code):
print(postal_code)
key='111df503a6114f138be4910b1c125437'
url = 'http://api.weatherbit.io/v2.0/current?city='+city+'&key='+key+'&postal_code='+str(postal_code)
response = requests.get(url)
print(requests, ">>>>>>>>>>>>",response.text, type(response.text))
j_response = json.loads(response.text)
print("***************************************************")
# print("response>>>>>>>",j_response, type(j_response))
print("***************************************************")
current_temp = j_response['data'][0]['temp']
uv_info = j_response['data'][0]['uv']
print(uv_info)
return current_temp
print(get_current_temperature('Mumbai',400065))