├── .gitignore ├── About.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── MyAlarm.py ├── PA.py ├── README.md ├── Record.py ├── SnakeGame.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ -------------------------------------------------------------------------------- /About.md: -------------------------------------------------------------------------------- 1 | # 🤖 About 2 | 3 | Since, voice based personal assistants have acquired a great deal of prominence in this time of smart homes and automated gadgets. These personal assistants can be handily designed to perform a significant number of our normal tasks by basically providing voice commands. 4 | 5 | 6 | The basic idea behind this Python Assistant is to create a simple stand-alone application that helps people in using the computer with an ease rather than feeling ignorant or computer illiterate and visually impared can also use the devices easily. 7 | 8 | 9 | A solid AI foundation is essential if any application of voice recognition technology is to be successful. 10 | 11 | 12 | The Python assistant will have unlimited features if integrated with Artificial Intelligence that incorporates Machine Learning, Deep Learning, Neural Networks and so on. And it can integrated with IoT, with the consolidation of these advancements, we will actually want to accomplish new heights. 13 | 14 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | ums945891@gmail.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Umesh Singh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MyAlarm.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import winsound # pip install playsound 3 | 4 | 5 | def alarm(Timing): 6 | altime = str(datetime.datetime.now().strptime(Timing, "%I:%M %p")) 7 | 8 | altime = altime[11:-3] 9 | print(altime) 10 | Hr_real = altime[:2] 11 | Hr_real = int(Hr_real) 12 | Min_real = altime[3:5] 13 | Min_real = int(Min_real) 14 | print(f"Done, alarm is set for {Timing}") 15 | 16 | while True: 17 | if Hr_real == datetime.datetime.now().hour: 18 | if Min_real == datetime.datetime.now().minute: 19 | print("Alarm is Ringing...") 20 | winsound.PlaySound('abc', winsound.SND_LOOP) 21 | 22 | elif Min_real < datetime.datetime.now().minute: 23 | break 24 | 25 | 26 | if __name__ == '__main__': 27 | alarm('09:21 PM') 28 | -------------------------------------------------------------------------------- /PA.py: -------------------------------------------------------------------------------- 1 | import pyttsx3 # pip install pyttsx3 2 | import datetime 3 | import speech_recognition as sr # pip install SpeechRecognition 4 | import pyaudio # pip install pipwin and then pipwin install pyaudio 5 | import wikipedia # pip install wikipedia 6 | import webbrowser 7 | import os 8 | import sys 9 | import smtplib 10 | from email.message import EmailMessage 11 | import pywhatkit # pip install pywhatkit 12 | import MyAlarm 13 | import ecapture as ec 14 | import pyjokes # pip install pyjokes 15 | from speedtest import Speedtest # pip install speedtest-cli 16 | from pywikihow import search_wikihow # pip install pywikihow 17 | import pyautogui # pip install pyAutoGUI 18 | import poetpy # pip install poetpy 19 | import random 20 | from forex_python.converter import CurrencyRates # pip install forex-python 21 | import requests # pip install requests 22 | import bs4 # pip install beautifulsoup4 23 | import time 24 | import wolframalpha # pip install wolframalpha 25 | from quote import quote # pip install quote 26 | import winshell as winshell # pip install winshell 27 | from geopy.geocoders import Nominatim # pip install geopy and pip install geocoder 28 | from geopy import distance 29 | import turtle 30 | import random 31 | import snake_game 32 | import record 33 | import requests 34 | from PIL import Image 35 | 36 | engine = pyttsx3.init() 37 | 38 | def fun_talk(audio): 39 | engine.say(audio) 40 | engine.runAndWait() 41 | 42 | def wish_user(): 43 | hour = int(datetime.datetime.now().hour) 44 | if hour >= 0 and hour < 12: 45 | fun_talk("Good Morning !") 46 | elif hour >= 12 and hour < 18: 47 | fun_talk("Good Afternoon !") 48 | else: 49 | fun_talk("Good Evening !") 50 | 51 | fun_talk("I am P.A. (Python Assistant). Tell me how may I help you.") 52 | 53 | 54 | def get_command(): 55 | rec = sr.Recognizer() 56 | with sr.Microphone() as source: 57 | print("Listening...") 58 | rec.pause_threshold = 1 59 | 60 | audio = rec.listen(source) 61 | 62 | try: 63 | print("Recognizing...") 64 | query = rec.recognize_google(audio, language='en-in') 65 | print(f"User said: {query}\n") 66 | except sr.UnknownValueError: 67 | print("Google Speech Recognition could not understand audio") 68 | return "None" 69 | except sr.RequestError as e: 70 | print("Could not request results from Google Speech Recognition service; {0}".format(e)) 71 | return "None" 72 | 73 | except Exception as e: 74 | print(e) 75 | print("Say that again please...") 76 | return "None" 77 | return query 78 | 79 | 80 | if __name__ == '__main__': 81 | wish_user() 82 | while True: 83 | query = get_command().lower() 84 | home_user_dir = os.path.expanduser("~") 85 | 86 | if 'wikipedia' in query: 87 | fun_talk('Searching Wikipedia') 88 | query = query.replace("wikipedia", "") 89 | results = wikipedia.summary(query, sentences=3) 90 | fun_talk("According to Wikipedia") 91 | print(results) 92 | fun_talk(results) 93 | 94 | elif ['images','image'] in query: 95 | fun_talk("Please provide the desired keywords to search related Images") 96 | txt=get_command() 97 | fun_talk("Providing Images of"+txt) 98 | response=requests.get("https://source.unsplash.com/random?{0}".format(txt)) 99 | file=open('sample_image.jpg','wb') 100 | file.write(response.content) 101 | img=Image.open(r"sample_image.jpg") 102 | img.show() 103 | file.close 104 | 105 | elif 'open youtube' in query: 106 | webbrowser.open("www.youtube.com") 107 | 108 | elif 'open google' in query: 109 | webbrowser.open("www.google.com") 110 | 111 | elif 'open cu login' in query: 112 | webbrowser.open("uims.cuchd.in/uims/") 113 | 114 | elif 'open blackboard' in query: 115 | webbrowser.open("cuchd.blackboard.com") 116 | 117 | elif 'open stack overflow' in query: 118 | webbrowser.open("stackoverflow.com") 119 | 120 | elif 'the time' in query: 121 | strTime = datetime.datetime.now().strftime("%H:%M:%S") 122 | fun_talk(f"The time is {strTime}") 123 | 124 | elif 'the date' in query: 125 | strDate = datetime.datetime.today().strftime('%Y-%m-%d') 126 | print(strDate) 127 | fun_talk(f"The date is {strDate}") 128 | 129 | elif 'open visual studio code' in query: 130 | os.startfile(home_user_dir + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\" 131 | "Programs\\Visual Studio Code\\Visual Studio Code") 132 | 133 | elif 'open eclipse' in query: 134 | os.startfile(home_user_dir + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\" 135 | "Programs\\Eclipse\\Eclipse IDE for Java Developers - 2020-06") 136 | 137 | elif 'open notepad' in query: 138 | os.startfile("C:\\Windows\\notepad.exe") 139 | 140 | elif 'open pycharm' in query: 141 | os.startfile("C:\\Program Files\\JetBrains\\PyCharm Community Edition 2020.1.1\\bin\\pycharm64.exe") 142 | 143 | elif 'open code blocks' in query: 144 | os.startfile(home_user_dir + "\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\" 145 | "Programs\\CodeBlocks\\CodeBlocks") 146 | 147 | elif 'open mozilla firefox' in query: 148 | os.startfile("C:\\Program Files\\Mozilla Firefox\\firefox.exe") 149 | 150 | elif 'open chrome' in query: 151 | os.startfile("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe") 152 | 153 | elif 'open whatsapp' in query: 154 | os.startfile(home_user_dir + "\\AppData\\Local\\WhatsApp\\WhatsApp.exe") 155 | 156 | elif 'open v l c' in query: 157 | os.startfile("C:\\Program Files\\VideoLAN\\VLC\\vlc.exe") 158 | 159 | elif 'who are you' in query: 160 | fun_talk("I am P.A. (Python Assistant), developed by Rishabh Ranjan, Himanshi, " 161 | "Rachit Dwivedi and Umesh Singh as a project in their college.") 162 | 163 | elif 'what you want to do' in query: 164 | fun_talk("I want to help people to do certain tasks on their single voice commands.") 165 | 166 | elif 'alexa' in query: 167 | fun_talk("I don't know Alexa, but I've heard of Alexa. If you have Alexa, " 168 | "I may have just triggered Alexa. If so, sorry Alexa.") 169 | 170 | elif 'google assistant' in query: 171 | fun_talk("He was my classmate, too intelligent guy. We both are best friends.") 172 | 173 | elif 'siri' in query: 174 | fun_talk("Siri, She's a competing virtual assistant on a competitor's phone. " 175 | "Not that I'm competitive or anything.") 176 | 177 | elif 'cortana' in query: 178 | fun_talk("I thought you'd never ask. So I've never thought about it.") 179 | 180 | elif 'python assistant' in query: 181 | fun_talk("Are you joking. You're coming in loud and clear.") 182 | 183 | elif 'what language you use' in query: 184 | fun_talk("I am written in Python and I generally speak english.") 185 | 186 | elif 'send email' in query: 187 | 188 | def send_mail(receiver, subject, message): 189 | 190 | server = smtplib.SMTP('smtp.gmail.com', 587) 191 | server.starttls() 192 | server.login('your_email@something.com', 'your_password') 193 | 194 | email = EmailMessage() 195 | email['From'] = 'your_email@something.com' 196 | email['To'] = receiver 197 | email['Subject'] = subject 198 | email.set_content(message) 199 | server.send_message(email) 200 | 201 | 202 | email_list = { 203 | 'Umesh': 'ums945891@gmail.com', 204 | 'Rishabh': 'rishabhran123@gmail.com', 205 | 'name': 'something@something.com', 206 | 'assitant': 'something@something.com' 207 | } 208 | 209 | 210 | def get_mail_info(): 211 | fun_talk('To whom you want to send email') 212 | name = get_command() 213 | receiver = email_list[name] 214 | print(receiver) 215 | fun_talk('What is the subject of your email?') 216 | subject = get_command() 217 | fun_talk('Tell me the text in your email') 218 | message = get_command() 219 | 220 | send_mail(receiver, subject, message) 221 | 222 | fun_talk('Hey lazy person. Your email is sent Successfully.') 223 | 224 | fun_talk('Do you want to send more email?') 225 | send_more = get_command() 226 | if 'yes' in send_more: 227 | get_mail_info() 228 | 229 | 230 | get_mail_info() 231 | 232 | elif 'play' in query: 233 | cmd_info = query.replace('play', '') 234 | fun_talk(f'Playing {cmd_info} ') 235 | print(cmd_info) 236 | pywhatkit.playonyt(cmd_info) 237 | 238 | elif 'search' in query: 239 | query = query.replace('search', '') 240 | pywhatkit.search(query) 241 | 242 | elif 'set alarm' in query: 243 | fun_talk("Tell me the time to set an Alarm. For example, set an alarm for 11:21 AM") 244 | a_info = get_command() 245 | a_info = a_info.replace('set an alarm for', '') 246 | a_info = a_info.replace('.', '') 247 | a_info = a_info.upper() 248 | MyAlarm.alarm(a_info) 249 | 250 | elif 'exit p a' in query: 251 | fun_talk("Exiting Sir...") 252 | sys.exit() 253 | 254 | elif 'close command prompt' in query: 255 | os.system("TASKKILL /F /IM cmd.exe") 256 | 257 | elif 'close firefox' in query: 258 | os.system("TASKKILL /F /IM firefox.exe") 259 | # subprocess.call(["taskkill", "/F", "/IM", "firefox.exe"]) 260 | 261 | elif "camera" or "take a photo" in query: 262 | ec.capture(0,"robo camera","img.jpg") 263 | 264 | elif 'close visual studio code' in query: 265 | os.system("TASKKILL /F /IM Code.exe") 266 | 267 | elif 'close eclipse' in query: 268 | os.system("TASKKILL /F /IM eclipse.exe") 269 | 270 | elif 'close notepad' in query: 271 | os.system("TASKKILL /F /IM notepad.exe") 272 | 273 | elif 'close pycharm' in query: 274 | os.system("TASKKILL /F /IM pycharm64.exe") 275 | 276 | elif 'close code blocks' in query: 277 | os.system("TASKKILL /F /IM codeblocks.exe") 278 | 279 | elif 'close chrome' in query: 280 | os.system("TASKKILL /F /IM chrome.exe") 281 | 282 | elif 'close whatsapp' in query: 283 | os.system("TASKKILL /F /IM WhatsApp.exe") 284 | 285 | elif 'close vlc' in query: 286 | os.system("TASKKILL /F /IM vlc.exe") 287 | 288 | elif 'close spotify' in query: 289 | os.system("TASKKILL /F /IM Spotify.exe") 290 | 291 | elif 'price of' in query: 292 | query = query.replace('price of', '') 293 | query = "https://www.amazon.in/s?k=" + query[-1] #indexing since I only want the keyword 294 | webbrowser.open(query) 295 | 296 | elif 'poem' in query: 297 | fun_talk('Poem of which author you want to listen?') 298 | auth = get_command() 299 | poem = poetpy.get_poetry('author', auth, 'title,linecount') 300 | poems = poetpy.get_poetry('author', auth, 'lines') 301 | 302 | poem_len = len(poem) 303 | # print(poem_len) 304 | poem_no = random.randint(1, poem_len) 305 | print("Title- ", poem[poem_no]['title']) 306 | fun_talk(f"Title- {poem[poem_no]['title']}") 307 | print("No. of lines-", poem[poem_no]['linecount']) 308 | fun_talk(f"No. of lines- {poem[poem_no]['linecount']}") 309 | poem_str = '\n' 310 | print("Poem-\n", poem_str.join(poems[poem_no]['lines'])) 311 | fun_talk(f"Poem-\n {poem_str.join(poems[poem_no]['lines'])}") 312 | 313 | elif 'resume' in query or 'pause' in query: 314 | pyautogui.press("playpause") 315 | 316 | elif 'previous' in query: 317 | pyautogui.press("prevtrack") 318 | 319 | elif 'next' in query: 320 | pyautogui.press("nexttrack") 321 | 322 | elif 'convert currency' in query: 323 | try: 324 | curr_list = { 325 | 'dollar': 'USD', 'taka': 'BDT', 'dinar': 'BHD', 326 | 'rupee': 'INR', 'afghani': 'AFN', 'real': 'BRL', 327 | 'yen': 'JPY', 'peso': 'ARS', 'pound': 'EGP', 'rial': 'OMR', 328 | 'lek': 'ALL', 'kwanza': 'AOA', 'manat': 'AZN', 'franc': 'CHF' 329 | } 330 | 331 | cur = CurrencyRates() 332 | # print(cur.get_rate('USD', 'INR')) 333 | fun_talk('From which currency u want to convert?') 334 | from_cur = get_command() 335 | src_cur = curr_list[from_cur.lower()] 336 | fun_talk('To which currency u want to convert?') 337 | to_cur = get_command() 338 | dest_cur = curr_list[to_cur.lower()] 339 | fun_talk('Tell me the value of currency u want to convert.') 340 | val_cur = float(get_command()) 341 | # print(val_cur) 342 | print(cur.convert(src_cur, dest_cur, val_cur)) 343 | 344 | except Exception as e: 345 | print("Couldn't get what you have said, Can you say it again??") 346 | 347 | elif 'covid-19' in query or 'corona' in query: 348 | fun_talk('For which region u want to see the Covid-19 cases. ' 349 | 'Overall cases in the world or any specific country?') 350 | c_query = get_command() 351 | if 'overall' in c_query or 'over all' in c_query or 'world' in c_query or 'total' in c_query or 'worldwide' in c_query: 352 | def world_cases(): 353 | try: 354 | url = 'https://www.worldometers.info/coronavirus/' 355 | info_html = requests.get(url) 356 | info = bs4.BeautifulSoup(info_html.text, 'lxml') 357 | info2 = info.find('div', class_='content-inner') 358 | new_info = info2.findAll('div', id='maincounter-wrap') 359 | # print(new_info) 360 | print('Worldwide Covid-19 information--') 361 | fun_talk('Worldwide Covid-19 information--') 362 | 363 | for i in new_info: 364 | head = i.find('h1', class_=None).get_text() 365 | counting = i.find('span', class_=None).get_text() 366 | print(head, "", counting) 367 | fun_talk(f'{head}: {counting}') 368 | 369 | except Exception as e: 370 | pass 371 | 372 | 373 | world_cases() 374 | 375 | elif 'country' in c_query or 'specific country' in c_query: 376 | def country_cases(): 377 | try: 378 | fun_talk('Tell me the country name.') 379 | c_name = get_command() 380 | c_url = f'https://www.worldometers.info/coronavirus/country/{c_name}/' 381 | data_html = requests.get(c_url) 382 | c_data = bs4.BeautifulSoup(data_html.text, 'lxml') 383 | new_data = c_data.find('div', class_='content-inner').findAll('div', id='maincounter-wrap') 384 | # print(new_data) 385 | print(f'Covid-19 information for {c_name}--') 386 | fun_talk(f'Covid-19 information for {c_name}') 387 | 388 | for j in new_data: 389 | c_head = j.find('h1', class_=None).get_text() 390 | c_counting = j.find('span', class_=None).get_text() 391 | print(c_head, "", c_counting) 392 | fun_talk(f'{c_head}: {c_counting}') 393 | 394 | except Exception as e: 395 | pass 396 | 397 | 398 | country_cases() 399 | 400 | elif 'weather' in query or 'temperature' in query: 401 | try: 402 | fun_talk("Tell me the city name.") 403 | city = get_command() 404 | api = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=eea37893e6d01d234eca31616e48c631" 405 | w_data = requests.get(api).json() 406 | weather = w_data['weather'][0]['main'] 407 | temp = int(w_data['main']['temp'] - 273.15) 408 | temp_min = int(w_data['main']['temp_min'] - 273.15) 409 | temp_max = int(w_data['main']['temp_max'] - 273.15) 410 | pressure = w_data['main']['pressure'] 411 | humidity = w_data['main']['humidity'] 412 | visibility = w_data['visibility'] 413 | wind = w_data['wind']['speed'] 414 | sunrise = time.strftime("%H:%M:%S", time.gmtime(w_data['sys']['sunrise'] + 19800)) 415 | sunset = time.strftime("%H:%M:%S", time.gmtime(w_data['sys']['sunset'] + 19800)) 416 | 417 | all_data1 = f"Condition: {weather} \nTemperature: {str(temp)}°C\n" 418 | all_data2 = f"Minimum Temperature: {str(temp_min)}°C \nMaximum Temperature: {str(temp_max)}°C \n" \ 419 | f"Pressure: {str(pressure)} millibar \nHumidity: {str(humidity)}% \n\n" \ 420 | f"Visibility: {str(visibility)} metres \nWind: {str(wind)} km/hr \nSunrise: {sunrise} " \ 421 | f"\nSunset: {sunset}" 422 | fun_talk(f"Gathering the weather information of {city}...") 423 | print(f"Gathering the weather information of {city}...") 424 | print(all_data1) 425 | fun_talk(all_data1) 426 | print(all_data2) 427 | fun_talk(all_data2) 428 | 429 | except Exception as e: 430 | pass 431 | 432 | elif 'month' in query or 'month is going' in query: 433 | def tell_month(): 434 | month = datetime.datetime.now().strftime("%B") 435 | fun_talk(month) 436 | 437 | tell_month() 438 | 439 | elif 'day' in query or 'day today' in query: 440 | def tell_day(): 441 | day = datetime.datetime.now().strftime("%A") 442 | fun_talk(day) 443 | 444 | tell_day() 445 | 446 | elif "calculate" in query: 447 | try: 448 | app_id = "JUGV8R-RXJ4RP7HAG" 449 | client = wolframalpha.Client(app_id) 450 | indx = query.lower().split().index('calculate') 451 | query = query.split()[indx + 1:] 452 | res = client.query(' '.join(query)) 453 | answer = next(res.results).text 454 | print("The answer is " + answer) 455 | fun_talk("The answer is " + answer) 456 | 457 | except Exception as e: 458 | print("Couldn't get what you have said, Can you say it again??") 459 | 460 | elif 'quote' in query or 'quotes' in query: 461 | fun_talk("Tell me the author or person name.") 462 | q_author = get_command() 463 | quotes = quote(q_author) 464 | quote_no = random.randint(1, len(quotes)) 465 | # print(len(quotes)) 466 | # print(quotes) 467 | print("Author: ", quotes[quote_no]['author']) 468 | print("-->", quotes[quote_no]['quote']) 469 | fun_talk(f"Author: {quotes[quote_no]['author']}") 470 | fun_talk(f"He said {quotes[quote_no]['quote']}") 471 | 472 | elif 'what' in query or 'who' in query: # or 'where' in query: 473 | 474 | client = wolframalpha.Client("JUGV8R-RXJ4RP7HAG") 475 | res = client.query(query) 476 | try: 477 | print(next(res.results).text) 478 | fun_talk(next(res.results).text) 479 | 480 | except StopIteration: 481 | print("No results found!!") 482 | 483 | elif 'empty recycle bin' in query or 'clear recycle bin' in query: 484 | try: 485 | winshell.recycle_bin().empty(confirm=False, show_progress=False, sound=True) 486 | print("Recycle Bin is cleaned successfully.") 487 | fun_talk("Recycle Bin is cleaned successfully.") 488 | 489 | except Exception as e: 490 | print("Recycle bin is already Empty.") 491 | fun_talk("Recycle bin is already Empty.") 492 | 493 | elif 'write a note' in query or 'make a note' in query: 494 | fun_talk("What should I write, sir??") 495 | note = get_command() 496 | file = open('Notes.txt', 'a') 497 | fun_talk("Should I include the date and time??") 498 | n_conf = get_command() 499 | if 'yes' in n_conf: 500 | str_time = datetime.datetime.now().strftime("%H:%M:%S") 501 | file.write(str_time) 502 | file.write(" --> ") 503 | file.write(note) 504 | fun_talk("Point noted successfully.") 505 | else: 506 | file.write("\n") 507 | file.write(note) 508 | fun_talk("Point noted successfully.") 509 | 510 | elif 'show me the notes' in query or 'read notes' in query: 511 | fun_talk("Reading Notes") 512 | file = open("Notes.txt", "r") 513 | data_note = file.readlines() 514 | # for points in data_note: 515 | print(data_note) 516 | fun_talk(data_note) 517 | 518 | elif 'distance' in query: 519 | geocoder = Nominatim(user_agent="Singh") 520 | fun_talk("Tell me the first city name??") 521 | location1 = get_command() 522 | fun_talk("Tell me the second city name??") 523 | location2 = get_command() 524 | 525 | coordinates1 = geocoder.geocode(location1) 526 | coordinates2 = geocoder.geocode(location2) 527 | 528 | lat1, long1 = coordinates1.latitude, coordinates1.longitude 529 | lat2, long2 = coordinates2.latitude, coordinates2.longitude 530 | 531 | place1 = (lat1, long1) 532 | place2 = (lat2, long2) 533 | 534 | distance_places = distance.distance(place1, place2) 535 | 536 | print(f"The distance between {location1} and {location2} is {distance_places}.") 537 | fun_talk(f"The distance between {location1} and {location2} is {distance_places}") 538 | 539 | elif 'screenshot' in query: 540 | sc = pyautogui.screenshot() 541 | sc.save('pa_ss.png') 542 | print("Screenshot taken successfully.") 543 | fun_talk("Screenshot taken successfully.") 544 | 545 | elif 'volume up' in query: 546 | pyautogui.press("volumeup") 547 | 548 | elif 'volume down' in query: 549 | pyautogui.press("volumedown") 550 | 551 | elif 'mute volume' in query: 552 | pyautogui.press("volumemute") 553 | 554 | elif 'shut down' in query: 555 | print("Do you want to shutdown you system?") 556 | fun_talk("Do you want to shutdown you system?") 557 | cmd = get_command() 558 | if 'no' in cmd: 559 | continue 560 | else: 561 | 562 | os.system("shutdown /s /t 1") 563 | 564 | elif 'restart' in query: 565 | print("Do you want to restart your system?") 566 | fun_talk("Do you want to restart your system?") 567 | cmd = get_command() 568 | if 'no' in cmd: 569 | continue 570 | else: 571 | 572 | os.system("shutdown /r /t 1") 573 | 574 | elif 'log out' in query: 575 | print("Do you want to logout from your system?") 576 | fun_talk("Do you want to logout from your system?") 577 | cmd = get_command() 578 | if 'no' in cmd: 579 | continue 580 | else: 581 | os.system("shutdown -l") 582 | 583 | elif 'joke' in query: 584 | joke = pyjokes.get_joke() 585 | print(joke) 586 | fun_talk(joke) 587 | 588 | elif 'internet speed' in query: 589 | st = Speedtest() 590 | print("Wait!! I am checking your Internet Speed...") 591 | fun_talk("Wait!! I am checking your Internet Speed...") 592 | dw_speed = st.download() 593 | up_speed = st.upload() 594 | dw_speed = dw_speed / 1000000 595 | up_speed = up_speed / 1000000 596 | print('Your download speed is', round(dw_speed, 3), 'Mbps') 597 | print('Your upload speed is', round(up_speed, 3), 'Mbps') 598 | fun_talk(f'Your download speed is {round(dw_speed, 3)} Mbps') 599 | fun_talk(f'Your upload speed is {round(up_speed, 3)} Mbps') 600 | 601 | elif 'send message on whatsapp' in query: 602 | phno_list = { 603 | 'Umesh': '+911234567890', 604 | 'Rishabh': '+919876543210', 605 | 'assitant': '+910000000000' 606 | } 607 | 608 | 609 | def send_whtmsg(): 610 | fun_talk('To whom you want to send message on WhatsApp') 611 | recepient = get_command() 612 | check_recep = phno_list[recepient] 613 | print(check_recep) 614 | fun_talk('Tell me the text in your message') 615 | msg = get_command() 616 | fun_talk('Do you want to send it immediately?') 617 | act_msg = get_command() 618 | if 'yes' in act_msg: 619 | hr = datetime.datetime.now().time().hour 620 | min = datetime.datetime.now().time().minute 621 | pywhatkit.sendwhatmsg(check_recep, msg, hr, min + 2) 622 | print('Hey lazy person. Your message is sent successfully.') 623 | else: 624 | fun_talk('At what time you want to send this message. For example, 11:21 PM') 625 | msg_time = get_command() 626 | 627 | hr = 12 628 | min = 52 629 | pywhatkit.sendwhatmsg(check_recep, msg, hr, min) 630 | print('Hey lazy person. Your message is sent successfully.') 631 | fun_talk('Do you want to send more WhatsApp messages?') 632 | more_msg = get_command() 633 | if 'yes' in more_msg: 634 | send_whtmsg() 635 | 636 | 637 | send_whtmsg() 638 | 639 | elif 'how to' in query: 640 | try: 641 | # query = query.replace('how to', '') 642 | max_results = 1 643 | data = search_wikihow(query, max_results) 644 | # assert len(data) == 1 645 | data[0].print() 646 | fun_talk(data[0].summary) 647 | except Exception as e: 648 | fun_talk('Sorry, I am unable to find the answer for your query.') 649 | 650 | elif 'news' in query or 'news headlines' in query: 651 | url = "https://news.google.com/news/rss" 652 | client = webbrowser(url) 653 | xml_page = client.read() 654 | client.close() 655 | page = bs4.BeautifulSoup(xml_page, 'xml') 656 | news_list = page.findAll("item") 657 | fun_talk("Today's top headlines are--") 658 | try: 659 | for news in news_list: 660 | print(news.title.text) 661 | # print(news.pubDate.text) 662 | fun_talk(f"{news.title.text}") 663 | # fun_talk(f"{news.pubDate.text}") 664 | print() 665 | 666 | except Exception as e: 667 | pass 668 | 669 | elif 'screen recording' in query: 670 | fun_talk('Press Q to stop and save recording') #Screen recorder functionality 671 | record.screen_record() 672 | 673 | elif 'snake game' in query: 674 | try: 675 | print("Starting the game!") 676 | fun_talk("Starting the game!") 677 | snake_game.game() 678 | except Exception as e: 679 | pass 680 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Assistant (PA) 2 | 3 | Python Assistant (PA) is a voice command based assistant service written in Python 3.9+. It can recognize human speech or voice, talk to user and execute basic commands. 4 | 5 | ## Features 6 | 7 | * Tells the current time or date or month or day [e.g. 'tell me time or date or day or month'] 8 | 9 | * Opens a web page [e.g. 'open google, 'open youtube', 'open stack overflow'] 10 | 11 | * Tells about general questions [e.g. 'what is the length of great wall of china', 'who is the prime minister of india'] 12 | 13 | * Play music on Youtube [e.g. 'play so high', 'play aatmvishwas'] 14 | 15 | * Increase/decrease the speakers master volume and also can mute speakers volume [e.g. 'volume up', 'volume down'] 16 | 17 | * Tells the internet speed i.e., upload and download speed [e.g. 'tell me the internet speed'] 18 | 19 | * Tells the weather for a particular city [e.g. 'tell me the weather in Noida'] 20 | 21 | * Opens MS Office suite applications [e.g. 'open word', 'open powerpoint'] 22 | 23 | * Set an alarm [e.g. 'set an alarm'] 24 | 25 | * Tells the latest daily news [e.g. 'tell me the news'] 26 | 27 | * Write notes for reminder [e.g. 'write a note'] 28 | 29 | * Read notes [e.g. 'read notes'] 30 | 31 | * Search on wikipedia [e.g. 'New Delhi wikipedia', 'Noida wikipedia'] 32 | 33 | * Guide us about something [e.g. 'how to drive a car', 'how to become an engineer'] 34 | 35 | * Send messages on Whatsapp [e.g. 'send message on whatsapp'] 36 | 37 | * Send emails [e.g. 'send email'] 38 | 39 | * Tells the distance between two cities [e.g. 'distance between Noida and Visakhapatnam'] 40 | 41 | * Clean the Recycle Bin [e.g. 'clear the recycle bin'] 42 | 43 | * Tells Quotes [e.g. 'tell me a quote'] 44 | 45 | * Tells the COVID-19 cases worldwide [e.g. 'tell me the covid-19 cases'] 46 | 47 | * Tells the COVID-19 cases for specific country [e.g. 'tell me the covid-19 cases'] 48 | 49 | * Tells Jokes [e.g. 'tell me a joke'] 50 | 51 | * Do Arithmetic operations [e.g. 'calculate five plus three hundred plus twenty five' or 'calculate 5 + 300 + 25'] 52 | 53 | * Convert currency [e.g. 'convert currency'] 54 | 55 | * Take screenshots [e.g. 'take a screenshot'] 56 | 57 | * Tells Poems [e.g. 'tell me a poem'] 58 | 59 | * Close applications [e.g. 'close pycharm', 'close google chrome', 'close spotify'] 60 | 61 | * Open applications [e.g. 'open eclipse', 'open notepad', 'open firefox'] 62 | 63 | * Shutdown or Restart computer [e.g. 'shutdown computer', 'restart computer'] 64 | 65 | * Searching anything on the internet [e.g. 'search Python', 'search uttar pradesh'] 66 | 67 | ## Requirements 68 | 69 | Python version 3.9+ or higher 70 | 71 | Either you can use CLI or you can use IDE (like PyCharm) 72 | 73 | ## Installation 74 | 75 | ### For Development Version 76 | 77 | - Press the Fork button, to save a copy of this repository on your GitHub account 78 | - Clone this repository by typing `git clone https://github.com//Python-Assistant.git` command in git bash 79 | - Create a New branch using `git branch new-branch` and move into the new branch using `git checkout new-branch` 80 | - Before pushing code to repository makes sure to pull the latest remote repository by `git remote add upstream https://github.com/Umesh-01/Python-Assistant.git` and `git pull upstream main`, and resolve any merge conflict if exists 81 | 82 | ### For Non-Development Version 83 | - Clone this repository by typing git clone `https://github.com/Umesh-01/Python-Assistant.git` command in git bash
84 | `OR`
85 | Download this repository by clicking on Download ZIP inside the Code button 86 | 87 | 88 | ## Contributing 89 | 90 | PRs are welcome 🙂 91 | 92 | If you find any issue just put it in the issue section 93 | 94 | Try to follow PEP 8 guidelines and add comments!! 95 | -------------------------------------------------------------------------------- /Record.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import psutil 3 | import numpy as np 4 | import os 5 | import pyautogui 6 | 7 | def screen_record(): #Screen Recording function 8 | 9 | user = psutil.users()[0].name #gets the user name 10 | f_path = "C:\\Users\\" + user + "\\Desktop" 11 | # f_path = input("Enter where u want to save the file") #can also have an option as to where the user wants to save the file 12 | if os.path.exists(f_path): 13 | save_file = os.path.join(f_path,"output.mp4") 14 | else: 15 | save_file ="output.mp4" #saves the file in the corresponding directory 16 | 17 | s_size = (1920,1080) 18 | fps = 10.0 #determines how fast the slow the playback speed will be 19 | 20 | fcc = cv2.VideoWriter_fourcc(*"mp4v") 21 | out = cv2.VideoWriter(save_file,fcc,fps,(s_size)) 22 | 23 | while 1: 24 | 25 | img = pyautogui.screenshot() 26 | frm = np.array(img) 27 | frm = cv2.cvtColor(frm,cv2.COLOR_BGR2RGB) 28 | cv2.imshow("recorder",frm) 29 | cv2.namedWindow("recorder",cv2.WINDOW_NORMAL) 30 | cv2.resizeWindow("recorder", 800,800) 31 | out.write(frm) 32 | 33 | key = cv2.waitKey(1) # q to close the window and stop recording 34 | if key == 113: 35 | break 36 | 37 | cv2.destroyAllWindows() 38 | out.release() 39 | -------------------------------------------------------------------------------- /SnakeGame.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | import random 3 | import time 4 | 5 | 6 | def game(): 7 | 8 | delay=0.1 9 | score=0 10 | highstscore=0 11 | 12 | #snake body 13 | bodies=[] 14 | 15 | #getting a screen 16 | s=turtle.Screen() 17 | s.title("Snake Game") 18 | s.bgcolor("black") 19 | s.setup(width=600,height=600) 20 | s.cv._rootwindow.resizable(False, False) 21 | 22 | #create head of Snake 23 | head=turtle.Turtle() 24 | head.speed(0) 25 | head.shape("circle") 26 | head.color("#79891A") 27 | head.fillcolor("#0CB968") 28 | head.penup() 29 | head.goto(0,0) 30 | head.direction="stop" 31 | 32 | #Food of Snake 33 | food=turtle.Turtle() 34 | food.speed(0) 35 | food.shape("turtle") 36 | food.color("yellow") 37 | food.fillcolor("#4ACB61") 38 | food.penup() 39 | food.ht() 40 | food.goto(0,200) 41 | food.st() 42 | 43 | #Game Score board 44 | sb=turtle.Turtle() 45 | sb.shape("square") 46 | sb.color("gray") 47 | sb.fillcolor("gray") 48 | sb.penup() 49 | sb.ht() 50 | sb.goto(-250,-250) 51 | sb.write("Score:0 | Highest Score:0") 52 | 53 | 54 | def moveup(): 55 | if head.direction!="down": 56 | head.direction="up" 57 | 58 | def movedown(): 59 | if head.direction!="up": 60 | head.direction="down" 61 | def moveleft(): 62 | if head.direction!="right": 63 | head.direction="left" 64 | def moveright(): 65 | if head.direction!="left": 66 | head.direction="right" 67 | 68 | def move(): 69 | if head.direction=="up": 70 | y=head.ycor() 71 | head.sety(y+20) 72 | if head.direction=="down": 73 | y=head.ycor() 74 | head.sety(y-20) 75 | if head.direction=="left": 76 | x=head.xcor() 77 | head.setx(x-20) 78 | if head.direction=="right": 79 | x=head.xcor() 80 | head.setx(x+20) 81 | 82 | #Game Keyboard 83 | s.listen() 84 | s.onkey(moveup,"Up") 85 | s.onkey(movedown,"Down") 86 | s.onkey(moveleft,"Left") 87 | s.onkey(moveright,"Right") 88 | 89 | 90 | #main loop 91 | 92 | while True: 93 | s.update() #this is to update the screen 94 | #Handle collission with border 95 | if head.xcor()>290: 96 | head.setx(-290) 97 | if head.xcor()<-290: 98 | head.setx(290) 99 | if head.ycor()>290: 100 | head.sety(-290) 101 | if head.ycor()<-290: 102 | head.sety(290) 103 | 104 | #chechk for collission with food 105 | if head.distance(food)<20: 106 | x=random.randint(-290,290) 107 | y=random.randint(-290,290) 108 | food.goto(x,y) 109 | 110 | #increase the length of snake 111 | body=turtle.Turtle() 112 | body.speed(0) 113 | body.penup() 114 | body.shape("circle") 115 | body.color("#79891A") 116 | body.fillcolor("#0CB968") 117 | bodies.append(body) #append new body 118 | 119 | #increase the score 120 | score+=5 121 | 122 | #change delay 123 | delay-=0.001 124 | 125 | #update the highestscore 126 | if score>highstscore: 127 | highstscore=score 128 | sb.clear() 129 | sb.write(f"Score: {score} | Highest Score: {highstscore}") 130 | 131 | #move the snake bodies 132 | for index in range(len(bodies)-1,0,-1): 133 | x=bodies[index-1].xcor() 134 | y=bodies[index-1].ycor() 135 | bodies[index].goto(x,y) 136 | 137 | if len(bodies)>0: 138 | x=head.xcor() 139 | y=head.ycor() 140 | bodies[0].goto(x,y) 141 | move() 142 | 143 | #check for collision with snake body 144 | for body in bodies: 145 | if body.distance(head)<20: 146 | time.sleep(1) 147 | head.goto(0,0) 148 | head.direction="stop" 149 | 150 | #hide bodies 151 | for body in bodies: 152 | body.ht() 153 | bodies.clear() 154 | 155 | 156 | score=0 157 | delay=0.1 158 | 159 | #update the score board 160 | sb.clear() 161 | sb.write(f"Score: {score} | Highest Score: {highstscore}") 162 | s.bye() 163 | time.sleep(delay) 164 | s.mainloop() 165 | 166 | 167 | if __name__ == '__main__': 168 | game() 169 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | beautifulsoup4==4.10.0 2 | forex_python==1.8 3 | geopy==2.2.0 4 | poetpy==1.1.1 5 | PyAudio==0.2.11 6 | pyautogui==0.9.53 7 | pygame==2.1.2 8 | pyjokes==0.6.0 9 | pyttsx3==2.90 10 | pywhatkit==5.3 11 | pywikihow==0.5.7 12 | quote==2.0.4 13 | requests==2.27.1 14 | SpeechRecognition==3.8.1 15 | speedtest==0.0.1 16 | wikipedia==1.4.0 17 | winshell==0.6 18 | wolframalpha==5.0.0 19 | --------------------------------------------------------------------------------