Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated script.py #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions script.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def speak(jarvis_speech):
gtts_speak(jarvis_speech)
else:
offline_speak(jarvis_speech)

def temperature(city):
api_add = f'http://api.openweathermap.org/data/2.5/weather?appid=1ff1ec03072dc3e27d75e920aebd67a9&q={city}&units=metric'

json_data = requests.get(api_add).json()
temp = json_data["main"]["temp"]
cond = json_data["weather"][0]["description"]
name = json_data["name"]
speak(f"temperature of {name} is {temp} degree celcius and the condition is {cond}")
print(f"temperature of {name} is {temp} degree celcius and the condition is {cond}")




def listen():
Expand Down Expand Up @@ -70,6 +82,11 @@ def listen():
except ImportError:
print("\nInstall SpeechRecognition to use this feature." +
"\nStarting text mode\n")
if "temperature of" in query:
speak("please wait")
idx = query.index("f")+ 2
city = query[idx:]
temperature(city)
if (args.gtts):
try:
from gtts import gTTS
Expand Down