hazırladığım asistanıma gaziantep için hava durumu hazırladım ancak tab larda bir sıkıntı oldu yardımcı olabilir misiniz İnteger ların konumunda hata gösteriyor
def hava_durumu():
API = "51018b60257b50207fc63de7c53af5e1"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
SEHIR_ISMI = "Gaziantep"
URL = BASE_URL + "appid=" + API + "&q=" + SEHIR_ISMI
gelen_veri = requests.get((URL))
gelen_veri_JSON = gelen_veri.json()
if(gelen_veri_JSON["cod"] != "404") in voice:
temp = gelen_veri_JSON["main"]["temp"]
description = gelen_veri_JSON["weather"][0]["description"]
pressure = gelen_veri_JSON["main"]["pressure"]
country = gelen_veri_JSON["sys"]["country"]
engine.say("temp : " + str(float(temp) - 273.15), gender=gender, rate=rate, pitch=pitch, vol=vol)
engine.say("description : " + str(description), gender=gender, rate=rate, pitch=pitch, vol=vol)
if "hava durumu" in voice:
hava_durumu()
aib
Şubat 6, 2022, 10:26öö
2
API = "51018b60257b50207fc63de7c53af5e1"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
SEHIR_ISMI = "Gaziantep"
URL = BASE_URL + "appid=" + API + "&q=" + SEHIR_ISMI
Bunlar çalışıyor, hatanız başka yerde…
import requests
import json
def hava_durumu():
API = "51018b60257b50207fc63de7c53af5e1"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
SEHIR_ISMI = "Gaziantep"
URL = BASE_URL + "appid=" + API + "&q=" + SEHIR_ISMI
gelen_veri = requests.get((URL))
gelen_veri_JSON = gelen_veri.json()
#print(gelen_veri_JSON)
if(gelen_veri_JSON["cod"] != "404"):
temp = gelen_veri_JSON["main"]["temp"]
description = gelen_veri_JSON["weather"][0]["description"]
pressure = gelen_veri_JSON["main"]["pressure"]
country = gelen_veri_JSON["sys"]["country"]
return temp, description, pressure, country
print(hava_durumu())
print halinde çalışıyor ama ben bunu asistanıma hava durumu diye soruğumda bana bunları çalıştırıp en son
print(hava_durumu())
bunu bana sesli okuması gerekiyor
Sesli okuma örneğini inceleyiniz.
bunu şöyle düşünün print li halini program başladı siz terminal kısmına hava durumu yazdınız
o da size hava durumunu gösterdi bu şekilde düşünyorum ama yapamadım
1 Beğeni
Süslemeleri siz yaparsınız artık…
import pyttsx3
import requests
import json
#"espeak" için
dil = 64
engine = pyttsx3.init()
engine.setProperty("rate", 150) #konuşma hızı
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[dil].id) #Türkçe
#Konuşma fonksiyonu
def speak(text):
engine.say(text)
engine.runAndWait()
def hava_durumu():
API = "51018b60257b50207fc63de7c53af5e1"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
SEHIR_ISMI = "Gaziantep"
URL = BASE_URL + "appid=" + API + "&q=" + SEHIR_ISMI
gelen_veri = requests.get((URL))
gelen_veri_JSON = gelen_veri.json()
#print(gelen_veri_JSON)
if(gelen_veri_JSON["cod"] != "404"):
temp = gelen_veri_JSON["main"]["temp"]
description = gelen_veri_JSON["weather"][0]["description"]
pressure = gelen_veri_JSON["main"]["pressure"]
country = gelen_veri_JSON["sys"]["country"]
return temp, description, pressure, country
print(hava_durumu())
speak(hava_durumu()[0])
speak(hava_durumu()[1])
speak(hava_durumu()[2])
speak(hava_durumu()[3])
engine.stop()
def hava_durumu():
API = "51018b60257b50207fc63de7c53af5e1"
SEHIR_ISMI = "Gaziantep"
BASE_URL = f"https://api.openweathermap.org/data/2.5/weather?appid={API}&q={SEHIR_ISMI}"
gelen_veri = requests.get((BASE_URL))
gelen_veri_JSON = gelen_veri.json()
celsius = float(gelen_veri_JSON["main"]["temp"]) - 273
return engine.say(str(int(celsius))+" santigrat derece",gender=gender, rate=rate, pitch=pitch, vol=vol)