Skip to content

BOT ASSISTANT  #479

Open
Open
@Siyabonga7767

Description

@Siyabonga7767

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions