chefmate 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
chefmate/__init__.py ADDED
File without changes
@@ -0,0 +1,70 @@
1
+ # browser_manager.py
2
+ import os
3
+ import subprocess
4
+ from colorama import Fore
5
+ from selenium import webdriver
6
+ from selenium.webdriver.chrome.service import Service
7
+ from webdriver_manager.chrome import ChromeDriverManager
8
+ from selenium.common.exceptions import WebDriverException
9
+
10
+ class BrowserManager:
11
+ """Manages browser session and web interactions"""
12
+
13
+ def __init__(self, config):
14
+ self.config = config
15
+ self.driver = None
16
+
17
+ def is_chrome_running(self):
18
+ """Check if Chrome is currently running (Windows only)"""
19
+ try:
20
+ tasks = subprocess.run(['tasklist'], capture_output=True, text=True).stdout.lower()
21
+ return 'chrome.exe' in tasks
22
+ except Exception:
23
+ return False # fallback safely
24
+
25
+ def initialize_driver(self):
26
+ """Initialize and configure Chrome WebDriver"""
27
+
28
+ if self.is_chrome_running():
29
+ print(f"{Fore.RED} Chrome is already running. Please close all Chrome windows before starting ChefMate.\n")
30
+ return False
31
+
32
+ options = webdriver.ChromeOptions()
33
+ options.add_experimental_option('excludeSwitches', ['enable-logging', 'enable-automation'])
34
+ options.add_experimental_option('useAutomationExtension', False)
35
+ options.add_argument('--log-level=3')
36
+
37
+ # Setup isolated profile directory
38
+ user_data_dir = self.config.get("chrome_user_data_dir")
39
+ if not user_data_dir:
40
+ user_data_dir = os.path.join(os.getcwd(), "chefmate_profile")
41
+ os.makedirs(user_data_dir, exist_ok=True)
42
+ options.add_argument(f"--user-data-dir={user_data_dir}")
43
+
44
+ profile = self.config.get("chrome_profile", "Default")
45
+ options.add_argument(f"--profile-directory={profile}")
46
+
47
+ # Optional: prevent common crash issues
48
+ options.add_argument("--no-sandbox")
49
+ options.add_argument("--disable-dev-shm-usage")
50
+ options.add_experimental_option("detach", True)
51
+
52
+ try:
53
+ self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
54
+ self.driver.execute_cdp_cmd(
55
+ "Page.addScriptToEvaluateOnNewDocument",
56
+ {"source": "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"}
57
+ )
58
+ return True
59
+ except WebDriverException as e:
60
+ if "user data directory is already in use" in str(e):
61
+ print(f"{Fore.RED} Chrome profile is already being used. Close all Chrome windows and try again.\n")
62
+ else:
63
+ print(f"{Fore.RED} Error initializing Chrome: {e}\n")
64
+ return False
65
+
66
+ def close(self):
67
+ """Close the browser"""
68
+ if self.driver:
69
+ self.driver.quit()
70
+ self.driver = None