forked from noobDevelopers/J.A.R.V.I.S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather.py
45 lines (38 loc) · 1.3 KB
/
weather.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def weathernews():
city_name="Bangalore"
api_key = "yourapikey"
base_url = "http://api.openweathermap.org/data/2.5/weather?"
url = base_url + "appid=" + api_key + "&q=" + city_name
response = requests.get(url)
x = response.json()
speak('Todays weather')
weather_details={}
if x["cod"] != "404":
y = x["main"]
current_temperature = y["temp"]
current_pressure = y["pressure"]
current_humidiy = y["humidity"]
z = x["weather"]
weather_description = z[0]["description"]
#weather_details.append(city_name)
weather_details["Temperature"]=int(int(current_temperature)-273.15)
weather_details["Pressure"]=current_pressure
weather_details["Humidity"]=current_humidiy
weather_details["Summary"] = weather_description
for key,value in weather_details.items():
speak(key)
speak(value)
speak('That is all for todays weather, have a good day!')
else:
speak('Unable to fetch todays weather')
if __name__ == '__main__':
speak_news()