Files
2025-05-21 07:55:46 +03:00

39 lines
1.1 KiB
Python

import asyncio
import webbrowser
from typing import Dict, Any
async def open_url(args: Dict[str, Any]) -> Dict[str, Any]:
"""
Opens a website in the default browser on Windows.
Args:
args: Dictionary containing 'url' (string) of the website to open.
Returns:
Dictionary with status message and input arguments.
Raises:
OSError: If opening the website fails.
"""
try:
# Get URL from args
url = args.get('url')
if not url:
raise ValueError("URL must be provided in args")
# Ensure URL has a scheme (http:// or https://)
if not url.startswith(('http://', 'https://')):
url = 'https://' + url
# Open website in default browser
success = await asyncio.to_thread(webbrowser.open, url)
if not success:
raise OSError("Failed to open the website")
return {
"message": f"Website {url} opened successfully",
"args": args
}
except Exception as e:
raise OSError(f"Error while opening website: {str(e)}")