From 209f40bfaee137728f64770a8e9d3869d2b3504c Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Thu, 14 Jan 2021 13:13:45 +0100 Subject: [PATCH] Chrome path in browser_settings. Chrome test done --- .gitignore | 1 + README.md | 11 +++++++++ .../TwitchChannelPointsMiner.py | 2 +- TwitchChannelPointsMiner/classes/Twitch.py | 6 ++--- .../classes/TwitchBrowser.py | 23 +++++++++++++++++-- .../classes/WebSocketsPool.py | 2 +- 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 695c2a1..42fd0f3 100644 --- a/.gitignore +++ b/.gitignore @@ -139,6 +139,7 @@ cython_debug/ # Custom files run.py +chromedriver* # Folders cookies/* diff --git a/README.md b/README.md index 95638ce..04ae165 100644 --- a/README.md +++ b/README.md @@ -72,3 +72,14 @@ If you already have a `twitch-cookies.pkl` and you don't want to login again ple +-- cookies | +-- your-twitch-username.pkl ``` + +## 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. +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 +), +``` \ No newline at end of file diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index ff88f4f..2b9b2bc 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -224,7 +224,7 @@ class TwitchChannelPointsMiner: if self.streamers[streamer_index].history != {}: logger.info( emoji.emojize( - f":coin: {self.streamers[streamer_index].print_history()}", + f":moneybag: {self.streamers[streamer_index].print_history()}", use_aliases=True, ) ) diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index ceaba52..e33a694 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -115,7 +115,7 @@ class Twitch: else: streamer.set_online() - def claim_channel_points_bonus(self, streamer, claim_id): + def claim_bonus(self, streamer, claim_id): logger.info( emoji.emojize( f":gift: Claiming the bonus for {streamer}!", use_aliases=True @@ -156,9 +156,7 @@ class Twitch: streamer.channel_points = community_points["balance"] # logger.info(f"{streamer.channel_points} channel points for {streamer.username}!") if community_points["availableClaim"] is not None: - self.claim_channel_points_bonus( - streamer, community_points["availableClaim"]["id"] - ) + self.claim_bonus(streamer, community_points["availableClaim"]["id"]) def make_predictions(self, event): decision = event.bet.calculate(event.streamer.channel_points) diff --git a/TwitchChannelPointsMiner/classes/TwitchBrowser.py b/TwitchChannelPointsMiner/classes/TwitchBrowser.py index 534eea9..34b7fa9 100644 --- a/TwitchChannelPointsMiner/classes/TwitchBrowser.py +++ b/TwitchChannelPointsMiner/classes/TwitchBrowser.py @@ -3,6 +3,7 @@ import logging import random import os import emoji +import platform from pathlib import Path from datetime import datetime @@ -16,7 +17,6 @@ from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction -from TwitchChannelPointsMiner.classes.Bet import Strategy TWITCH_URL = "https://www.twitch.tv/" @@ -46,11 +46,20 @@ class BrowserSettings: do_screenshot: bool = False, show: bool = True, browser: Browser = Browser.FIREFOX, + chrome_path: str = None, ): self.timeout = timeout self.do_screenshot = do_screenshot self.show = show self.browser = browser + self.chrome_path = ( + chrome_path + if chrome_path is not None + else os.path.join( + Path().absolute(), + ("chromedriver" + (".exe" if platform.system() == "Windows" else "")), + ) + ) class TwitchBrowser: @@ -137,7 +146,17 @@ class TwitchBrowser: options.add_argument("--no-sandbox") options.add_argument("--disable-setuid-sandbox") options.add_experimental_option("excludeSwitches", ["enable-logging"]) - self.browser = webdriver.Chrome(options=options) + + if os.path.isfile(self.settings.chrome_path) is True: + self.browser = webdriver.Chrome(self.settings.chrome_path, options=options) + else: + logger.warning( + emoji.emojize( + f":wrench: The path {self.settings.chrome_path} is not valid", + use_aliases=True, + ) + ) + self.browser = webdriver.Chrome(options=options) # Private method __ - We can instantiate webdriver only with init_browser def __init_firefox(self): diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 9dd1ee6..1733410 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -144,7 +144,7 @@ class WebSocketsPool: streamer_index = get_streamer_index( ws.streamers, message_data["claim"]["channel_id"] ) - ws.twitch.claim_channel_points_bonus( + ws.twitch.claim_bonus( ws.streamers[streamer_index], message_data["claim"]["id"] )