first commit

This commit is contained in:
MoonDev
2025-05-21 07:55:46 +03:00
commit 96ea504b10
28 changed files with 919 additions and 0 deletions

Binary file not shown.

Binary file not shown.

41
utils/config.py Normal file
View File

@@ -0,0 +1,41 @@
import os
import yaml
from typing import Dict, Any
import asyncio
async def read_config(config_file):
"""
Reads and parses a YAML configuration file from the parent directory.
Args:
'config_file' (str) with the name of the YAML file.
If not provided, defaults to 'config.yaml'.
Returns:
Dictionary with the parsed configuration and input arguments.
Raises:
OSError: If the file cannot be read or parsed.
"""
try:
# Get the config file name from args, default to 'config.yaml'
config_file = "./config/"+config_file
# Construct path to the parent directory
parent_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
config_path = os.path.join(parent_dir, config_file)
# Check if file exists
if not os.path.exists(config_path):
raise OSError(f"Configuration file '{config_file}' not found in parent directory")
# Read and parse YAML file
with open(config_path, 'r', encoding='utf-8') as f:
config_data = yaml.safe_load(f)
if config_data is None:
raise OSError(f"Configuration file '{config_file}' is empty or invalid")
return config_data
except yaml.YAMLError as e:
raise OSError(f"Error parsing YAML file: {str(e)}")
except Exception as e:
raise OSError(f"Error reading configuration file: {str(e)}")

45
utils/windows_toast.py Normal file
View File

@@ -0,0 +1,45 @@
from win10toast import ToastNotifier
import asyncio
from typing import Dict, Any
async def show_notification(args: Dict[str, Any]) -> Dict[str, Any]:
"""
Displays a system notification in the Windows system tray (bottom-right corner).
Args:
args: Dictionary containing 'title' (str), 'message' (str), and optional 'duration' (int, in seconds).
Returns:
Dictionary with status message and input arguments.
Raises:
ValueError: If required 'title' or 'message' arguments are missing.
OSError: If the notification fails to display.
"""
try:
# Check for required arguments
title = args.get('title')
message = args.get('message')
if not title or not message:
raise ValueError("Both 'title' and 'message' are required in args")
# Optional duration (default to 5 seconds)
duration = args.get('duration', 5)
if not isinstance(duration, int) or duration < 1:
raise ValueError("'duration' must be a positive integer")
# Initialize the notifier
toaster = ToastNotifier()
# Show notification (run in a separate thread to avoid blocking)
await asyncio.get_event_loop().run_in_executor(
None,
lambda: toaster.show_toast(
title=title,
msg=message,
duration=duration,
threaded=True
)
)
return {"message": "Notification displayed successfully", "args": args}
except Exception as e:
raise OSError(f"Error displaying notification: {str(e)}")