-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhava_durumu.py
More file actions
23 lines (19 loc) · 1.01 KB
/
Copy pathhava_durumu.py
File metadata and controls
23 lines (19 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import requests
import json
## Gelecek commitlerde uygulama arayüzü eklenecek.
sehir = input("Şehir adi giriniz: ")
origin_url = f"http://api.openweathermap.org/data/2.5/weather?q={sehir}&appid=e5d4d1ef34e7df15187c034c597ee14d"
response = requests.get(origin_url) ## Sitedeki verileri çektik ve response değişkenine atadık.
if response.status_code==404:
print("Sehir ismi hatali.") ## Dönen status kodu kullanarak, girilen isim hatali mi diye kontrol ettik.
else:
jsonResponse = json.loads(response.text) ## İsimde hata yoksa devam edip verileri json olarak parçalara böldük.
sicaklik=str(jsonResponse["main"]["temp"] - 272.15)
hissedilen=str(jsonResponse["main"]["feels_like"] -272.15 ) ## Kelvinden Celcius'a çevirdik.
basinc=str(jsonResponse["main"]["pressure"])
nem=str(jsonResponse["main"]["humidity"])
print("İsim: " + sehir )
print("Sicaklik: " + sicaklik + " °C" )
print("Hissedilen Sicaklik: "+ hissedilen + " °C" )
print("Basinc: "+ basinc + " Paskal")
print("Nem Orani: "+ "%" + nem )