diff --git a/sniper/__main__.py b/sniper/__main__.py index 84c7795..12adb8e 100644 --- a/sniper/__main__.py +++ b/sniper/__main__.py @@ -68,14 +68,22 @@ def read_config(): return notification_config, customer -async def main(): - colorama.init() - print(const.HEADER) - log_format = '%(asctime)s nvidia-sniper: %(message)s' +def setup_logging(): + log_format = '%(asctime)s %(name)s: %(message)s' fh = logging.FileHandler('sniper.log', encoding='utf-8') sh = logging.StreamHandler(sys.stdout) + logging.getLogger().name = 'nvidia-sniper' logging.basicConfig(level=logging.INFO, format=log_format, handlers=[fh, sh]) + logging.getLogger('WDM').disabled = True + logging.getLogger('apprise').disabled = True + logging.getLogger('apprise.URLBase').disabled = True + + +async def main(): + colorama.init() + print(const.HEADER) + setup_logging() notification_config, customer = read_config() diff --git a/sniper/notifications.py b/sniper/notifications.py index fad673c..722bba6 100644 --- a/sniper/notifications.py +++ b/sniper/notifications.py @@ -24,7 +24,7 @@ def __init__(self, notification_config, notification_queue, target_gpu): def send_notifications(self, notification_type): for name, service in self.config['services'].items(): - logging.info(f'Sending notifications to {name}') + logging.info(f'Sending {notification_type} notification to {name}...') apobj = apprise.Apprise() apobj.add(service['url']) title = f"{notification_type.replace('-',' ').title()} - {self.gpu['name']}" diff --git a/sniper/webdriver.py b/sniper/webdriver.py index d2ab2f6..40e5bba 100644 --- a/sniper/webdriver.py +++ b/sniper/webdriver.py @@ -11,26 +11,31 @@ from webdriver_manager.firefox import GeckoDriverManager except Exception: logging.error( - 'Could not import all required modules. '\ - 'Please run the following command again:\n\n'\ + 'Could not import all required modules. ' + 'Please run the following command again:\n\n' '\tpipenv install\n') exit() -def get_default_profile(): + +def get_profile_path(): if platform == 'linux' or platform == 'linux2': - mozilla_profile = Path(os.getenv('HOME')) / '.mozilla' / 'firefox' + profile_path = Path(os.getenv('HOME')) / '.mozilla' / 'firefox' elif platform == 'darwin': - mozilla_profile = Path(os.getenv('HOME')) / \ + profile_path = Path(os.getenv('HOME')) / \ 'Library' / 'Application Support' / 'Firefox' elif platform == 'win32': - mozilla_profile = Path(os.getenv('APPDATA')) / 'Mozilla' / 'Firefox' - if not mozilla_profile.exists(): - raise FileNotFoundError("Mozilla profile doesn't exist and/or can't be located on this machine.") + profile_path = Path(os.getenv('APPDATA')) / 'Mozilla' / 'Firefox' + if not profile_path.exists(): + raise FileNotFoundError( + "Mozilla profile doesn't exist and/or can't be located on this machine.") + return profile_path + - mozilla_profile_ini = mozilla_profile / 'profiles.ini' +def get_default_profile(profile_path): + mozilla_profile_ini = profile_path / 'profiles.ini' profile = configparser.ConfigParser() profile.read(mozilla_profile_ini) - return mozilla_profile / profile.get('Profile0', 'Path') + return profile.get('Profile0', 'Path') def prepare_sniper_profile(default_profile_path): @@ -42,13 +47,16 @@ def prepare_sniper_profile(default_profile_path): def create(): - default_profile_path = get_default_profile() - profile = prepare_sniper_profile(default_profile_path) - driver = webdriver.Firefox(firefox_profile=profile, executable_path=GeckoDriverManager().install()) + profile_path = get_profile_path() + default_profile = get_default_profile(profile_path) + logging.info(f'Launching Firefox using default profile: {default_profile}') + profile = prepare_sniper_profile(profile_path / default_profile) + driver = webdriver.Firefox( + firefox_profile=profile, executable_path=GeckoDriverManager().install()) if os.path.isfile('./recaptcha_solver-5.7-fx.xpi'): - logging.info('ReCaptcha solver detected, enabled') + logging.info('ReCaptcha solver extension detected and installed') extension_path = os.path.abspath("recaptcha_solver-5.7-fx.xpi") driver.install_addon(extension_path, temporary=True) else: - logging.info('ReCaptcha solver not found') - return driver \ No newline at end of file + logging.info('ReCaptcha solver extension not found') + return driver