From d759d2ff0a906db7afd4870dd992a054cfac780c Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Tue, 19 Jan 2021 21:40:55 +0100 Subject: [PATCH] Update Readme for Windows. Executable path also for geckodriver (Firefox) --- README.md | 9 +++++- TwitchChannelPointsMiner/__init__.py | 4 +-- TwitchChannelPointsMiner/classes/Streamer.py | 10 +++--- TwitchChannelPointsMiner/classes/Twitch.py | 3 ++ .../classes/TwitchBrowser.py | 32 +++++++++++++------ setup.py | 2 +- 6 files changed, 43 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 3e97233..7c9d96a 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,13 @@ If you already have a `twitch-cookies.pkl` and you don't want to login again ple | +-- your-twitch-username.pkl ``` +## Windows +Other users have find multiple problems on Windows my suggestion are: + - Stop use Windows :stuck_out_tongue_closed_eyes: + - Suppress the emoji in logs with `logger_settings=LoggerSettings(emoji=False)` + - Download the geckodriver from here: https://github.com/mozilla/geckodriver/releases/ and extract in the same folder of this project. For other issue with geckodriver just googling: https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path + + ## Use Chrome instead Firefox If you prefer Chrome instead Firefox please download the WebDriver matching with your Chrome version and OS from this link: https://chromedriver.chromium.org/downloads. Extract the archivie, copy the chromedriver file in this project folder. @@ -88,6 +95,6 @@ Edit your run.py file and the browser_settings should something like this: ```python browser_settings=BrowserSettings( browser=Browser.CHROME, - chrome_path="/path/of/your/chromedriver" # If no path was provided the script will try to search automatically + driver_path="/path/of/your/chromedriver" # If no path was provided the script will try to search automatically ), ``` \ No newline at end of file diff --git a/TwitchChannelPointsMiner/__init__.py b/TwitchChannelPointsMiner/__init__.py index df355ca..d9841ab 100644 --- a/TwitchChannelPointsMiner/__init__.py +++ b/TwitchChannelPointsMiner/__init__.py @@ -1,3 +1,3 @@ -__version__ = "2.0.0" - +# -*- coding: utf-8 -*- +__version__ = "2.1.1" from .TwitchChannelPointsMiner import TwitchChannelPointsMiner diff --git a/TwitchChannelPointsMiner/classes/Streamer.py b/TwitchChannelPointsMiner/classes/Streamer.py index 972057b..92406a5 100644 --- a/TwitchChannelPointsMiner/classes/Streamer.py +++ b/TwitchChannelPointsMiner/classes/Streamer.py @@ -28,13 +28,15 @@ class Streamer: def set_offline(self): self.offline_at = time.time() - self.is_online = False - logger.info(f"{self} is Offline!", extra={"emoji": ":sleeping:"}) + if self.is_online: + self.is_online = False + logger.info(f"{self} is Offline!", extra={"emoji": ":sleeping:"}) def set_online(self): self.online_at = time.time() - self.is_online = True - logger.info(f"{self} is Online!", extra={"emoji": ":partying_face:"}) + if not self.is_online: + self.is_online = True + logger.info(f"{self} is Online!", extra={"emoji": ":partying_face:"}) def print_history(self): return ", ".join( diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index 15be24d..aeeab9d 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -82,6 +82,9 @@ class Twitch: "User-Agent": USER_AGENT, }, ) + logger.debug( + f"Data: {json_data}, Status code: {response.status_code}, Content: {response.json()}" + ) return response.json() def get_broadcast_id(self, streamer): diff --git a/TwitchChannelPointsMiner/classes/TwitchBrowser.py b/TwitchChannelPointsMiner/classes/TwitchBrowser.py index e00d0bf..0035605 100644 --- a/TwitchChannelPointsMiner/classes/TwitchBrowser.py +++ b/TwitchChannelPointsMiner/classes/TwitchBrowser.py @@ -56,7 +56,7 @@ class BrowserSettings: save_html: bool = False, # Options for debug show: bool = True, browser: Browser = Browser.FIREFOX, - chrome_path: str = None, + driver_path: str = None, ): self.timeout = timeout self.implicitly_wait = implicitly_wait @@ -65,12 +65,15 @@ class BrowserSettings: self.save_html = save_html self.show = show self.browser = browser - self.chrome_path = ( - chrome_path - if chrome_path is not None + self.driver_path = ( + driver_path + if driver_path is not None else os.path.join( Path().absolute(), - ("chromedriver" + (".exe" if platform.system() == "Windows" else "")), + ( + ("chromedriver" if browser == Browser.CHROME else "geckodriver") + + (".exe" if platform.system() == "Windows" else "") + ), ) ) @@ -170,11 +173,11 @@ class TwitchBrowser: ) options.add_experimental_option("excludeSwitches", ["enable-logging"]) - if os.path.isfile(self.settings.chrome_path) is True: - self.browser = webdriver.Chrome(self.settings.chrome_path, options=options) + if os.path.isfile(self.settings.driver_path) is True: + self.browser = webdriver.Chrome(self.settings.driver_path, options=options) else: logger.warning( - f"The path {self.settings.chrome_path} is not valid", + f"The path {self.settings.driver_path} is not valid. Use default path", extra={"emoji": ":wrench:"}, ) self.browser = webdriver.Chrome(options=options) @@ -195,7 +198,18 @@ class TwitchBrowser: fp.set_preference("startup.homepage_welcome_url", "about:blank") fp.set_preference("startup.homepage_welcome_url.additional", "about:blank") - self.browser = webdriver.Firefox(options=options, firefox_profile=fp) + if os.path.isfile(self.settings.driver_path) is True: + self.browser = webdriver.Firefox( + executable_path=self.settings.driver_path, + options=options, + firefox_profile=fp, + ) + else: + logger.warning( + f"The path {self.settings.driver_path} is not valid. Use default path", + extra={"emoji": ":wrench:"}, + ) + self.browser = webdriver.Firefox(options=options, firefox_profile=fp) def __debug(self, event, method): if self.settings.do_screenshot: diff --git a/setup.py b/setup.py index 9a7ae11..df0f376 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def read(fname): setuptools.setup( name="Twitch-Channel-Points-Miner-v2", - version="2.0.0", + version="2.1.1", author="Tkd-Alex (Alessandro Maggio)", author_email="alex.tkd.alex@gmail.com", description="A simple script that will watch a stream for you and earn the channel points.",