-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_online.py
More file actions
58 lines (50 loc) · 2.51 KB
/
Copy pathfunction_online.py
File metadata and controls
58 lines (50 loc) · 2.51 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#from cgitb import text
from time import strftime
import requests
from datetime import datetime
from tabulate import tabulate
import pyttsx3
#from decouple import config
engine =pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
engine.setProperty("rate", 175)
def speak(txt):
engine.say(txt)
engine.runAndWait()
def weath():
while True:
API_KEY = ('bd9032b1b36cc1642b3c5528c1949c96')
location = input("Enter The Name Of The City/country : ")
weather = "https://api.openweathermap.org/data/2.5/weather?q="+ location +"&appid="+API_KEY
api_link = requests.get(weather)
api_data = api_link.json()
if api_data['cod'] == '404':
print("Invalid City: '{}', please check the city name".format(location))
speak("Invalid City: '{}', please check the city name".format(location))
else:
temp_city = ((api_data['main']['temp'])-273.15)
weathe_desc = api_data['weather'][0]['description']
hmdt = api_data['main']['humidity']
wind_speed = api_data['wind']['speed']
date_time = datetime.now().strftime("%d %b %Y || %I:%M:%S: %p")
tabel_heading = [f"Live Weather Status For {location.upper()} || {date_time}", "Reports"]
mydata = [
[f"Current Temperature In - {location.upper()}", f"{temp_city:.2f}"],
[f"Current Weather Description In - {location.upper()}", f"{weathe_desc}"],
[f"Current Humidity In - {location.upper()}", f"{hmdt}'%'"],
[f"Current Wind Speed In - {location.upper()}", f"{wind_speed}'kmph'"]
]
print(tabulate(mydata,headers=tabel_heading, tablefmt="grid"))
speak(f"current temperature in {location} : {temp_city:.2f}")
speak(f"current weather discription in {location} {weathe_desc}")
speak(f"current humidity in {location} {hmdt} percentage")
speak(f"current wind speed in {location} {wind_speed} kilo meter per hour")
quest = input("Do You Want To Continue....??? : ")
if quest == 'y' or quest == 'yes':
print("Thank You For Using Again The Ovila Live Weather Detector !!!")
speak("thank you for using again the olivia live weather detector")
else:
print("The Olivia Live Weather Detector Is Now Stoped !!!")
speak("the olivia live weather detector is now stoped")
break