From 6e1d61f6a561def5b2ef0230a2728e8d79fc4349 Mon Sep 17 00:00:00 2001 From: psavarmattas Date: Sat, 13 Mar 2021 09:44:14 +0530 Subject: [PATCH] Beefing Up! v2.o Release Source Code --- .gitignore | 0 .vscode/settings.json | 1 - __pycache__/weather.cpython-38.pyc | Bin 844 -> 257 bytes index.md | 25 +++++++++---- main.py | 49 +++++++++++++++++--------- readme.md | 25 +++++++++---- weather.py | 54 +++-------------------------- 7 files changed, 73 insertions(+), 81 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.vscode/settings.json b/.vscode/settings.json index 03e2224..7a73a41 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,2 @@ { - "python.pythonPath": "C:\\Users\\puran.MANEESHA\\anaconda3\\envs\\alexa\\python.exe" } \ No newline at end of file diff --git a/__pycache__/weather.cpython-38.pyc b/__pycache__/weather.cpython-38.pyc index 9b106e632a32c896f8a645bf24e638d8e6f16d4a..6ecb5ddc6e5809b030e7ed98a3836cd929df13c0 100644 GIT binary patch delta 140 zcmX@Z*2rWN%FD~e00aR#-U+Xn7#JRdILLqz$Z-JTVjduo!Vtxf!WhMv!W7J)$vjz; zQJGagqokx@;%99mKTW1v?1=@L@!6@Bx46qw6H78ui{eX*a#k`FF$492iC<;WX1?9={OlgvwuRI>>Hlv3%^>tAb{;NWIj_~n ze=0>0)rN@Np++>CA}Oj9onnF^Mbiri^aVsS3h@FWX+YN*NZ)A00OQQ0#@7`40mij< zgGd&#)LcZw0*hu9<`h~A^9pkcZMC0QSOA^cSD4Ju0_3jHw-hPT8OTqpSy}{pV$IQ6 zC{VPB=-eWjF!Mg9^Q1(zBeYbyRkfpoXn7z+$Q#wF8+w%>1pfkDF#tAl!%D#VRq6`2 zx>{MUCj6@?djJ>CTNn;J;<&ZdmDSGXdVQm}(dpG|by(@vp4Znlq0{TG!)BB^--?W< zZWwxW>-Lw*DDlYke2E2<L`hBaeFGQko$H&c_U-ktB+6`ODgJWVh5oV6ISm4JWep zl8D%DCNat`e!eT)IfO7^qT$FK1>R*|D7?Urp6xOgFvs&9)tj@|YBe1O=VRc)35Vcv za0I(_+`cMp>5(*(JudMX4}4cf=mYnPc^@OdF@~Jh3?gXOz$zx*d4$Iq|d#VdxoF>tg lP~FgrQ9#E-cxkI({zR#wjwe#mEo|xLRIsU;nl+IU{trWO`jG$t diff --git a/index.md b/index.md index 5efe645..01b667d 100644 --- a/index.md +++ b/index.md @@ -1,6 +1,6 @@ # **Create your own virtual assistant with just a few lines code (Using only PYTHON)** -_`Last Updated: December 22' 2020`_ +_`Last Updated: March 13' 2020`_ Hello & Welcome to this git page. Here I just created my own virtual assistant with just a few lines of code. It is not an @@ -12,7 +12,7 @@ step by step with me and by the end of it you will have your own virtual assistant up & running as a charm. To learn more about how I did it you can watch my YouTube -video on this or [click here](). +video on this or [click here](https://www.youtube.com/channel/UCz6SDxk2KQqJAD6Ra_YPm6A). ## Pre-Requisites: 1. Python Interpreter (Like [PyCharm](https://www.jetbrains.com/pycharm/)) @@ -30,8 +30,13 @@ video on this or [click here](). -> [pyjokes](https://pypi.org/project/pyjokes/) +-> [wolframalpha](https://pypi.org/project/wolframalpha/) + 5. Basic knowledge of how Python works & computers work 6. A will to explore +7. Get API keys for the following to test your assistant yourself or +just use the one I provide you with but it is better to use your API keys +so that you don't bottle neck you assistant. When all the above pre-requisites are there and ready you can start to work on your own virtual assistant. Please follow each @@ -55,25 +60,31 @@ resolved before opening an issues. `pip install pyjokes` +`pip install wolframalpha` + + _Install this if necessary (Only when the code gives error)_ `pip install pyaudio` 3. Copy the code given in main.py (in this git) & you will have the code up & running on your pc. _(Note: Creating two different files for weather & main you will have to import weather.py in the main.py file by using the `import weather` code in the main.py, therefore please make sure that the code for it is there or an error will be produced while running the weather command in the assistant.)_ -4. If you want to learn how this code actually works the go [watch my YouTube video]() for a better understanding. +4. If you want to learn how this code actually works the go [watch my YouTube video](https://www.youtube.com/channel/UCz6SDxk2KQqJAD6Ra_YPm6A) for a better understanding. ### For Linux/MacOs users: 1. Learn all the above commands on terminal. 2. Make sure to use pip3, because in linux pip refers for python2 and pip3 refers to python3. -3. Install these too - `pip3 install pyAudio`. +3. Install this too - `pip3 install pyAudio`. -## Feature List (v1.0): +## Feature List (v2.0): 1. Play videos on YouTube. -2. Search wikipedia with your queries. +2. Search Wikipedia with your queries. 3. Search google with your queries. 4. Listen to jokes. -5. Ask for the weather (only New Delhi, India available right now). \ No newline at end of file +5. Ask for the weather (Anywhere in the world). +6. It can solve complex math problems for you. +7. Ask it for today's date & time. +8. Say "thanks" or "thank you" and the assistant will appreciate you. \ No newline at end of file diff --git a/main.py b/main.py index 9c5d967..328bc3f 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 PSMForums. All rights reserved. +# Copyright (c) 2021 PSMForums. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -16,7 +16,10 @@ import pywhatkit import datetime import wikipedia import pyjokes +import wolframalpha import weather +import requests, json +import pprint listener = sr.Recognizer() engine = pyttsx3.init() @@ -77,23 +80,35 @@ if __name__ == "__main__": elif 'joke' in command: talk('Let me get you laughing...') talk(pyjokes.get_joke()) - elif 'weather' in command: - command = command.replace('weather', '') - if weather.response.status_code == 200: - talk('The Weather In:') - talk(weather.weather_city) - print(weather.weather_city) - talk(weather.weather_temperature) - print(weather.weather_temperature) - talk(weather.weather_humidity) - print(weather.weather_humidity) - talk(weather.weather_pressure) - print(weather.weather_pressure) - talk(weather.weather_report) - print(weather.weather_report) + elif "what is the weather in" in command: + command = command.split(" ") + location = str(command[5]) + url = weather.weather_url + "appid=" + weather.api_key + "&q=" + location + js = requests.get(url).json() + if js["cod"] != "404": + weather = js["main"] + temp = weather["temp"] + hum = weather["humidity"] + desc = js["weather"][0]["description"] + resp_string = "The temperature at " + location + " in Kelvin is " + str(temp) + " \nThe humidity is " + str(hum) + "\nand \nThe weather description is "+ str(desc) + print(resp_string) + talk(resp_string) else: - talk(weather.weather_error) - print(weather.weather_error) + print("City Not Found") + talk("City Not Found") + elif 'calculate' in command: + app_id = "JWP25T-Y434EXL697" #Your API key here + client = wolframalpha.Client(app_id) + indx = command.lower().split().index('calculate') + query = command.split()[indx + 1:] + res = client.query(' '.join(query)) + answer = next(res.results).text + print('The answer is ' + answer) + talk('The answer is:' + answer) + elif 'thank you' in command: + talk('Your welcome, Happy to help you') + elif 'thanks' in command: + talk('Your welcome, Happy to help you') elif 'stop' in command: break else: diff --git a/readme.md b/readme.md index 5efe645..01b667d 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # **Create your own virtual assistant with just a few lines code (Using only PYTHON)** -_`Last Updated: December 22' 2020`_ +_`Last Updated: March 13' 2020`_ Hello & Welcome to this git page. Here I just created my own virtual assistant with just a few lines of code. It is not an @@ -12,7 +12,7 @@ step by step with me and by the end of it you will have your own virtual assistant up & running as a charm. To learn more about how I did it you can watch my YouTube -video on this or [click here](). +video on this or [click here](https://www.youtube.com/channel/UCz6SDxk2KQqJAD6Ra_YPm6A). ## Pre-Requisites: 1. Python Interpreter (Like [PyCharm](https://www.jetbrains.com/pycharm/)) @@ -30,8 +30,13 @@ video on this or [click here](). -> [pyjokes](https://pypi.org/project/pyjokes/) +-> [wolframalpha](https://pypi.org/project/wolframalpha/) + 5. Basic knowledge of how Python works & computers work 6. A will to explore +7. Get API keys for the following to test your assistant yourself or +just use the one I provide you with but it is better to use your API keys +so that you don't bottle neck you assistant. When all the above pre-requisites are there and ready you can start to work on your own virtual assistant. Please follow each @@ -55,25 +60,31 @@ resolved before opening an issues. `pip install pyjokes` +`pip install wolframalpha` + + _Install this if necessary (Only when the code gives error)_ `pip install pyaudio` 3. Copy the code given in main.py (in this git) & you will have the code up & running on your pc. _(Note: Creating two different files for weather & main you will have to import weather.py in the main.py file by using the `import weather` code in the main.py, therefore please make sure that the code for it is there or an error will be produced while running the weather command in the assistant.)_ -4. If you want to learn how this code actually works the go [watch my YouTube video]() for a better understanding. +4. If you want to learn how this code actually works the go [watch my YouTube video](https://www.youtube.com/channel/UCz6SDxk2KQqJAD6Ra_YPm6A) for a better understanding. ### For Linux/MacOs users: 1. Learn all the above commands on terminal. 2. Make sure to use pip3, because in linux pip refers for python2 and pip3 refers to python3. -3. Install these too - `pip3 install pyAudio`. +3. Install this too - `pip3 install pyAudio`. -## Feature List (v1.0): +## Feature List (v2.0): 1. Play videos on YouTube. -2. Search wikipedia with your queries. +2. Search Wikipedia with your queries. 3. Search google with your queries. 4. Listen to jokes. -5. Ask for the weather (only New Delhi, India available right now). \ No newline at end of file +5. Ask for the weather (Anywhere in the world). +6. It can solve complex math problems for you. +7. Ask it for today's date & time. +8. Say "thanks" or "thank you" and the assistant will appreciate you. \ No newline at end of file diff --git a/weather.py b/weather.py index 34c5156..15e1d9b 100644 --- a/weather.py +++ b/weather.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020 PSMForums. All rights reserved. +# Copyright (c) 2021 PSMForums. All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -9,52 +9,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# importing requests and json -import requests, json +# API Key +api_key = "a4212b9586f6bf848e1c47839ebfc5e9" #Your API Key here -# base URL -BASE_URL = "https://api.openweathermap.org/data/2.5/weather?" - -# City Name -CITY = "New Delhi" - -# API key -API_KEY = "a4212b9586f6bf848e1c47839ebfc5e9" - -# Updating the URL -URL = BASE_URL + "q=" + CITY + "&appid=" + API_KEY - -# HTTP request -response = requests.get(URL) - -# checking the status code of the request - -if response.status_code == 200: - - # getting data in the json format - data = response.json() - - # getting the main dict block - main = data['main'] - - # getting temperature - temperature = main['temp'] - - # getting the humidity - humidity = main['humidity'] - - # getting the pressure - pressure = main['pressure'] - - # weather report - - report = data['weather'] - weather_city = f"{CITY:-^30}" - weather_temperature = f"Temperature: {temperature}" - weather_humidity = f"Humidity: {humidity}" - weather_pressure = f"Pressure: {pressure}" - weather_report = f"Weather Report: {report[0]['description']}" - -else: - # showing the error message - weather_error = "Error in the HTTP request please try again" +# Base URL +weather_url = "http://api.openweathermap.org/data/2.5/weather?"