-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeathercheck.py
28 lines (17 loc) · 969 Bytes
/
Weathercheck.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
# prepared by Marcin Idzik (Pr0soft)
import requests #we import the libarary for making HTTP requests in Python
while True: #endless loop
print() # to add empty line to console
user_input = input('What is city name for which to check temperature: ') # takes input from user for a city value
response = requests.get('http://api.openweathermap.org/data/2.5/weather?q='+user_input+'&APPID=eba1d2a48d8ef5168c95997d840b2fd2') # connectcs to openweathermap.org API to get data
print()
print ('Establishing Connection to API.....')
print()
if response.status_code == 200:
print(' Connection Sucesfull\n')
jason_data = response.json()
jason_temp = jason_data['main']['temp'] # extraction of temperature from Json
celcius_temp = jason_temp - 273
print("Current temperature in "+user_input+" is: " +str(celcius_temp)[:3]+" °C\n")
else:
print(' Check Connection, unable to connnect')