Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
83 lines (71 loc) · 2.29 KB
/
Copy pathutils.py
File metadata and controls
83 lines (71 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Utility functions for Stonic voice assistant
"""
import os
import logging
import datetime
import random
from typing import List, Dict, Any
# Import settings from config
from config import (
USER_NAME,
APPLICATIONS,
WEBSITES,
GREETING_RESPONSES,
UNKNOWN_COMMAND_RESPONSES,
FAREWELL_RESPONSES,
LOG_FILE,
LOG_LEVEL
)
# Configure logging
logging_level = getattr(logging, LOG_LEVEL, logging.INFO)
logging.basicConfig(
level=logging_level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(LOG_FILE),
logging.StreamHandler()
]
)
logger = logging.getLogger("Stonic")
def get_time() -> str:
"""Get the current time as a string"""
now = datetime.datetime.now()
time_str = now.strftime("%I:%M %p")
return f"It's {time_str}, {USER_NAME}."
def get_date() -> str:
"""Get the current date as a string"""
now = datetime.datetime.now()
date_str = now.strftime("%A, %B %d, %Y")
return f"Today is {date_str}, {USER_NAME}."
def get_random_response(responses: List[str]) -> str:
"""Get a random response from a list of responses"""
return random.choice(responses)
def create_directory_if_not_exists(directory_path: str) -> None:
"""Create a directory if it doesn't exist"""
if not os.path.exists(directory_path):
os.makedirs(directory_path)
logger.info(f"Created directory: {directory_path}")
def log_command(command: str, successful: bool = True) -> None:
"""Log a voice command and its execution status"""
status = "successful" if successful else "failed"
logger.info(f"Command '{command}' execution {status}")
def extract_website_name(command: str) -> str:
"""Extract website name from a command"""
words = command.lower().split()
for word in words:
if word in WEBSITES:
return word
return None
def extract_app_name(command: str) -> str:
"""Extract application name from a command"""
command = command.lower()
for app in APPLICATIONS:
if app in command:
return app
# Handle special cases
if "visual studio code" in command or "vs code" in command:
return "vscode"
if "file explorer" in command or "windows explorer" in command:
return "explorer"
return None