Description
Screen_Recording_20250115_143026_Code.Editor.mp4
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()