|
| 1 | +import pyttsx3 |
| 2 | +import webbrowser |
| 3 | +import datetime |
| 4 | +import pywhatkit |
| 5 | +import requests |
| 6 | + |
| 7 | +# Initialize the text-to-speech engine |
| 8 | +search = pyttsx3.init("sapi5") |
| 9 | + |
| 10 | +print("Sk. Salahuddin - Morning 01 Batch") |
| 11 | + |
| 12 | +# Set the voice to a female voice |
| 13 | +voices = search.getProperty("voices") |
| 14 | +search.setProperty("voice", voices[-1].id) |
| 15 | + |
| 16 | +def speak(text): |
| 17 | + search.say(text) |
| 18 | + search.runAndWait() |
| 19 | + |
| 20 | +def esshan(): |
| 21 | + hour = datetime.datetime.now().hour |
| 22 | + if hour >= 0 and hour < 12: |
| 23 | + speak("Good Morning!") |
| 24 | + elif hour >= 12 and hour < 18: |
| 25 | + speak("Good Afternoon") |
| 26 | + elif hour >= 18 and hour < 19: |
| 27 | + speak("Good evening") |
| 28 | + else: |
| 29 | + speak("Good night!") |
| 30 | + |
| 31 | +# Opening Welcome or you can set greetings in here: |
| 32 | +speak("Welcome. Sheikh Salahuddin, how may I help you?") |
| 33 | +esshan() |
| 34 | + |
| 35 | +def get_weather(city): |
| 36 | + # API URL with your API key |
| 37 | + url = f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid=API_KEY&units=metric' |
| 38 | + |
| 39 | + # Send an HTTP GET request to the API and get the response |
| 40 | + response = requests.get(url) |
| 41 | + |
| 42 | + # Check if the API call was successful |
| 43 | + if response.status_code == 200: |
| 44 | + # Parse the JSON response to get the weather information |
| 45 | + weather = response.json() |
| 46 | + |
| 47 | + # Extract the relevant weather information from the JSON response |
| 48 | + temperature = weather['main']['temp'] |
| 49 | + humidity = weather['main']['humidity'] |
| 50 | + description = weather['weather'][0]['description'] |
| 51 | + |
| 52 | + # Return the weather report for the city |
| 53 | + return f"The temperature in {city} is {temperature} Kelvin. The humidity is {humidity}% and the weather is {description}." |
| 54 | + else: |
| 55 | + # Return an error message if the API call was not successful |
| 56 | + return "Unable to get the weather report. Please try again later." |
| 57 | + |
| 58 | +get_weather("khulna") |
| 59 | + |
| 60 | +while True: |
| 61 | + # Get from input by user |
| 62 | + user_input = input("Enter your text: ").lower() |
| 63 | + |
| 64 | + # If you want to shut down it use this three 3 keywords : good bye / ok bye / turn off |
| 65 | + if "good bye" in user_input or "ok bye" in user_input or "turn off" in user_input: |
| 66 | + speak('Take care, and see you later, Bye!') |
| 67 | + break |
| 68 | + |
| 69 | + # AI talks or say it everytime when user gives input |
| 70 | + speak("Please wait for a few seconds, I'm opening now") |
| 71 | + |
| 72 | + # Check if the user wants the weather report |
| 73 | + if 'weather' in user_input: |
| 74 | + # Ask for the city name |
| 75 | + search.say("Sure, which city?") |
| 76 | + search.runAndWait() |
| 77 | + |
| 78 | + # Get the city name from the user |
| 79 | + city = input("Enter the city name: ") |
| 80 | + |
| 81 | + # Get the weather report for the city |
| 82 | + weather_report = get_weather(city) |
| 83 | + |
| 84 | + # Speak the weather report |
| 85 | + speak(weather_report) |
| 86 | + |
| 87 | + # Open YouTube if the user wants to go to YouTube |
| 88 | + if "youtube" in user_input: |
| 89 | + search.say("OK, What do you want to search from YouTube?") |
| 90 | + search.runAndWait() |
| 91 | + search_youtube = input("Enter:--> Open YouTube / Search on YouTube / Play on YouTube: ") |
| 92 | + |
| 93 | + # Open YouTube if the user wants to go to YouTube |
| 94 | + if "open youtube" in search_youtube: |
| 95 | + search.say("Opning YouTube, Please wait for a while!") |
| 96 | + search.runAndWait() |
| 97 | + webbrowser.open("https://www.youtube.com/") |
| 98 | + |
| 99 | + # Open YouTube search if the user wants search on YouTube |
| 100 | + elif "search youtube" in search_youtube: |
| 101 | + search.say("What do you want to search from YouTube?") |
| 102 | + search.runAndWait() |
| 103 | + search_youtube_items = input("Give your search keyword: ").lower() |
| 104 | + search.say("Opening your search items from YouTube, just wait for a while") |
| 105 | + search.runAndWait() |
| 106 | + webbrowser.open(f"https://www.youtube.com/results?search_query={search_youtube_items}") |
| 107 | + |
| 108 | + # Play on YouTube if the user wants to go to play anything from YouTube |
| 109 | + elif "play" in search_youtube: |
| 110 | + search.say("What do you want to Playing on YouTube?") |
| 111 | + search.runAndWait() |
| 112 | + song = input("Enter search :") |
| 113 | + search.say("You want to listen from YouTube " + song) |
| 114 | + search.runAndWait() |
| 115 | + pywhatkit.playonyt(song) |
| 116 | + |
| 117 | + # From the user is asked to know your local time and date together |
| 118 | + elif 'time' in user_input: |
| 119 | + now = datetime.datetime.now() |
| 120 | + date = now.strftime('%Y-%m-%d') |
| 121 | + clock = now.strftime('%I:%M %p') |
| 122 | + speak(f"Today's date is {date} and the current time is {clock}") |
| 123 | + |
| 124 | +#--------------------Single Date and Single Time area Start----------------------- |
| 125 | + |
| 126 | +# কমেন্ট করা আছে কমেন্ট টি মুছে ব্যবহার করুন - যদি শুধু তারিখ (Date) অথবা সময় (Time) ব্যবহার করতে চান |
| 127 | +# Commented Use Delete Comment - If you want to use only Date or Time |
| 128 | + |
| 129 | + # From the user is asked to know your only local time |
| 130 | + # শুধু সময় (Only Time) |
| 131 | + # elif 'time' in user_input: |
| 132 | + # clock = datetime.datetime.now().strftime('%I:%M %p') |
| 133 | + # speak(f"Your local time is {clock}") |
| 134 | + |
| 135 | + # From the user is asked to know your only local date |
| 136 | + # শুধু তারিখ (Only Date) |
| 137 | + # elif 'date' in user_input: |
| 138 | + # date = datetime.datetime.now().strftime('%Y-%m-%d') |
| 139 | + # speak(f"Your local time is {date}") |
| 140 | + |
| 141 | +#---------------------Single Date and Single Time area END------------------------ |
| 142 | + |
| 143 | + # From the user is asked if he wants to open Facebook |
| 144 | + elif "facebook" in user_input: |
| 145 | + search.say("What do you want to search from Facebook?") |
| 146 | + search.runAndWait() |
| 147 | + search_from_facebook = input("Enter:--> Open Facebook / Facebook Profile / Facebook Settings / Facebook Reel / Facebook Messenger / Facebook Video / Facebook Notification: ").lower() |
| 148 | + |
| 149 | + # Open Facebook if the user wants to go to Facebook |
| 150 | + if "open facebook" in search_from_facebook: |
| 151 | + search.say("Opning Facebook, Please wait for a while!") |
| 152 | + search.runAndWait() |
| 153 | + webbrowser.open("https://www.facebook.com/") |
| 154 | + |
| 155 | + # Open Facebook profile if the user wants to go to Facebook profile |
| 156 | + elif "facebook profile" in search_from_facebook: |
| 157 | + search.say("Opening Facebook profile") |
| 158 | + search.runAndWait() |
| 159 | + webbrowser.open(f"https://www.facebook.com/profile.php?=facebook%20{search_from_facebook}") |
| 160 | + |
| 161 | + # Open Facebook settings if the user wants to go to Facebook settings |
| 162 | + elif "facebook settings" in search_from_facebook: |
| 163 | + search.say("Opning Facebook settings") |
| 164 | + search.runAndWait() |
| 165 | + webbrowser.open(f"https://www.facebook.com/settings/?tab=account{search_from_facebook}") |
| 166 | + |
| 167 | + # Open Facebook Reel if the user wants to go to Facebook Reel |
| 168 | + elif "facebook reel" in search_from_facebook: |
| 169 | + search.say("Opning Facebook Reel") |
| 170 | + search.runAndWait() |
| 171 | + webbrowser.open(f"https://www.facebook.com/reel/?s=ifu{search_from_facebook}") |
| 172 | + |
| 173 | + # Open Facebook Messenger if the user wants to go to Facebook Messenger |
| 174 | + elif "facebook messenger" in search_from_facebook: |
| 175 | + search.say("Opning Facebook Messenger") |
| 176 | + search.runAndWait() |
| 177 | + webbrowser.open(f"https://www.facebook.com/messages/t/{search_from_facebook}") |
| 178 | + |
| 179 | + # Open Facebook Video if the user wants to go to Facebook Video |
| 180 | + elif "facebook video" in search_from_facebook: |
| 181 | + search.say("Opning Facebook Video") |
| 182 | + search.runAndWait() |
| 183 | + webbrowser.open(f"https://www.facebook.com/video/") |
| 184 | + |
| 185 | + # Open Facebook Notifications if the user wants to go to Facebook Notifications |
| 186 | + elif "facebook notification" in search_from_facebook: |
| 187 | + search.say("Opning Facebook Video") |
| 188 | + search.runAndWait() |
| 189 | + webbrowser.open(f"https://www.facebook.com/notifications{search_from_facebook}") |
| 190 | + |
| 191 | + # Search Google Map if the user wants to search for something |
| 192 | + elif "map" in user_input: |
| 193 | + search.say("What do you want to search from Google Map?") |
| 194 | + search.runAndWait() |
| 195 | + search_from_map = input("Enter Google map / City: ").lower() |
| 196 | + |
| 197 | + # Search for Google map |
| 198 | + if "google map" in search_from_map: |
| 199 | + search.say("Opning Google Map, Please wait for a while!") |
| 200 | + search.runAndWait() |
| 201 | + webbrowser.open(f"https://www.google.com/maps/") |
| 202 | + |
| 203 | + # Search for Google map for to know city location |
| 204 | + elif "city" in search_from_map: |
| 205 | + search.say("Give me a city name") |
| 206 | + search.runAndWait() |
| 207 | + city_name = input("Give your city name: ").lower() |
| 208 | + search.say("Opening your entire city, just wait for a while") |
| 209 | + search.runAndWait() |
| 210 | + webbrowser.open(f"https://www.google.com/maps/place/{city_name}") |
| 211 | + |
| 212 | + # Search Google if the user wants to search for something |
| 213 | + elif "google" in user_input: |
| 214 | + search.say("What do you want to search from Google?") |
| 215 | + search.runAndWait() |
| 216 | + search_items = input("Give your search keyword: ").lower() |
| 217 | + search.say("Opening your search items, just wait for a while") |
| 218 | + search.runAndWait() |
| 219 | + webbrowser.open(f"https://www.google.com/search?q={search_items}") |
0 commit comments