Skip to content

Commit 020874a

Browse files
API-With-Python
1 parent 68e7459 commit 020874a

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

API-With-Python

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//importing requests package to deal with http
2+
import requests
3+
city = input("Enter your city name: ")
4+
// To get API --> https://openweathermap.org/
5+
api_address = "http://api.openweathermap.org/data/2.5/weather?appid={ADD-YOUR-API-KEY}&q={}".format(city)
6+
//used get method to conect with the API
7+
// json method is used to convert JSON into python format JSON.
8+
json_data = requests.get(api_address).json()
9+
//indexing the weather and temp from the JSON
10+
output = json_data['weather'][0]['main'] 'and temperature is ' json_data['main']['temp']
11+
print("The weather is {} in {}.").format(output, city)

0 commit comments

Comments
 (0)