Beefing Up! v2.o Release Source Code
This commit is contained in:
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -1,3 +1,2 @@
|
||||
{
|
||||
"python.pythonPath": "C:\\Users\\puran.MANEESHA\\anaconda3\\envs\\alexa\\python.exe"
|
||||
}
|
||||
Binary file not shown.
25
index.md
25
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).
|
||||
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.
|
||||
49
main.py
49
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:
|
||||
|
||||
25
readme.md
25
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).
|
||||
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.
|
||||
54
weather.py
54
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?"
|
||||
|
||||
Reference in New Issue
Block a user