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

BOT ASSISTANT #479

Open
Siyabonga7767 opened this issue Jan 15, 2025 · 0 comments
Open

BOT ASSISTANT #479

Siyabonga7767 opened this issue Jan 15, 2025 · 0 comments

Comments

@Siyabonga7767
Copy link

Screenshot_20250115_142958_Code Editor.jpg

Screen_Recording_20250115_143026_Code.Editor.mp4

Screenshot_20250115_142947_Code Editor.jpg

Screenshot_20250115_143004_Code Editor.jpg

import datetime
import webbrowser
import os
import sys

def greet_user():
"""Greet the user based on the time of the day."""
current_hour = datetime.datetime.now().hour
if current_hour < 12:
return "Good morning!"
elif current_hour < 18:
return "Good afternoon!"
else:
return "Good evening!"

def get_date_time():
"""Return the current date and time."""
now = datetime.datetime.now()
return f"Today is {now.strftime('%A, %B %d, %Y')} and the time is {now.strftime('%I:%M %p')}."

def open_website(website):
"""Open a website in the browser."""
webbrowser.open(website)
return f"Opening {website}..."

def play_music():
"""Play music (or simulate it by opening a file or app)."""
music_folder = os.path.expanduser("~") + "/Music"
if os.path.exists(music_folder):
os.system(f"start {music_folder}")
return "Opening your music folder..."
else:
return "Music folder not found!"

def shut_down():
"""Shut down the program."""
sys.exit("Shutting down the assistant. Goodbye!")

def handle_command(command):
"""Handle the user's command."""
if "hello" in command:
return greet_user()
elif "time" in command or "date" in command:
return get_date_time()
elif "open" in command:
if "website" in command:
return open_website("https://www.google.com")
else:
return "I can only open websites at the moment."
elif "music" in command:
return play_music()
elif "exit" in command or "quit" in command:
shut_down()
else:
return "Sorry, I didn't understand that."

def run_assistant():
"""Run the assistant in a loop, processing user input."""
print("Hello, I'm your assistant. How can I help you today?")
while True:
try:
user_input = input("You: ").lower() # Taking user input
except EOFError:
print("\nInput stream closed. Exiting assistant.")
break
response = handle_command(user_input)
print("Assistant: " + response)

if name == "main":
run_assistant()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant