From a9cf39f28607507309c81f2c8cb797a79d9cf00c Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Fri, 22 Jan 2021 12:46:24 +0100 Subject: [PATCH] Improve less logging option #10 --- TwitchChannelPointsMiner/TwitchChannelPointsMiner.py | 8 +++++--- TwitchChannelPointsMiner/classes/Bet.py | 2 +- TwitchChannelPointsMiner/classes/TwitchBrowser.py | 12 ++++++++---- TwitchChannelPointsMiner/classes/WebSocketsPool.py | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index e48238ca..be40cdcf 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -98,7 +98,7 @@ def run(self, streamers: list = [], followers=False): streamers += [fw for fw in followers_array if fw not in streamers] logger.info( - f"Loading data for {len(streamers)} streamers. This operation can take a while ...", + f"Loading data for {len(streamers)} streamers. Please wait ...", extra={"emoji": ":nerd_face:"}, ) for streamer_username in streamers: @@ -137,7 +137,7 @@ def run(self, streamers: list = [], followers=False): self.minute_watcher_thread = threading.Thread( target=self.twitch.send_minute_watched_events, args=(self.streamers,) ) - self.minute_watcher_thread.daemon = True + # self.minute_watcher_thread.daemon = True self.minute_watcher_thread.start() self.ws_pool = WebSocketsPool( @@ -146,6 +146,7 @@ def run(self, streamers: list = [], followers=False): streamers=self.streamers, bet_settings=self.bet_settings, events_predictions=self.events_predictions, + less_printing=self.logger_settings.less ) topics = [ PubsubTopic( @@ -185,13 +186,14 @@ def run(self, streamers: list = [], followers=False): WebSocketsPool.handle_websocket_reconnection(self.ws_pool.ws) def end(self, signum, frame): - # logger.info("Please wait, this operation can take a while ...") if self.twitch_browser is not None: self.twitch_browser.browser.quit() self.running = self.twitch.running = False self.ws_pool.end() + self.minute_watcher_thread.join() + self.__print_report() time.sleep(3.5) # Do sleep for ending browser and threads diff --git a/TwitchChannelPointsMiner/classes/Bet.py b/TwitchChannelPointsMiner/classes/Bet.py index 22cdff1e..e2a1ac72 100644 --- a/TwitchChannelPointsMiner/classes/Bet.py +++ b/TwitchChannelPointsMiner/classes/Bet.py @@ -76,7 +76,7 @@ def update_outcomes(self, outcomes): self.__clear_outcomes() def __repr__(self): - return f"Bet(TotalUsers={self.total_users}, TotalPoints={self.total_points}), Decision={self.decision})\n\t\tOutcome0({self.outcomes[0]})\n\t\tOutcome1({self.outcomes[1]})" + return f"Bet(TotalUsers={self.total_users}, TotalPoints={self.total_points}), Decision={self.decision})\n\t\tOutcome0({self.get_outcome(0)})\n\t\tOutcome1({self.get_outcome(1)})" def get_outcome(self, index): outcome = self.outcomes[index] diff --git a/TwitchChannelPointsMiner/classes/TwitchBrowser.py b/TwitchChannelPointsMiner/classes/TwitchBrowser.py index 29bfb857..0528cc2e 100644 --- a/TwitchChannelPointsMiner/classes/TwitchBrowser.py +++ b/TwitchChannelPointsMiner/classes/TwitchBrowser.py @@ -4,6 +4,7 @@ import os import platform +from millify import millify from pathlib import Path from datetime import datetime from enum import Enum, auto @@ -367,7 +368,7 @@ def start_bet(self, event: EventPrediction): else: for attempt in range(0, self.settings.max_attempts): logger.info( - f"Start betting at {event.streamer.chat_url} for {event}", + f"Start betting for {event}", extra={"emoji": ":wrench:"}, ) self.browser.get(event.streamer.chat_url) @@ -419,11 +420,14 @@ def place_bet(self, event: EventPrediction): decision = event.bet.calculate(event.streamer.channel_points) if decision["choice"]: selector_index = 1 if decision["choice"] == "A" else 2 - decision_outcome = event.bet.get_outcome(selector_index - 1) + logger.info( + f"Decision: {event.bet.get_outcome(selector_index - 1)}", + extra={"emoji": ":wrench:"}, + ) try: logger.info( - f"Going to write: {decision['amount']} on input {decision['choice']}: {decision_outcome}", + f"Going to write: {decision['amount']} channel points on input {decision['choice']}", extra={"emoji": ":wrench:"}, ) if ( @@ -439,7 +443,7 @@ def place_bet(self, event: EventPrediction): if self.__click_on_vote(event, selector_index) is True: self.__debug(event, "click_on_vote") event.bet_placed = True - time.sleep(random.uniform(10, 20)) + time.sleep(random.uniform(5, 10)) except Exception: logger.error("Exception raised", exc_info=True) else: diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 2780207c..171d13e5 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -241,7 +241,7 @@ def on_message(ws, message): place_bet_thread.start() logger.info( - f"Thread should start and place the bet after: {event.closing_bet_after(current_timestamp)}s for the event: {ws.events_predictions[event_id]}", + f"Place the bet after: {event.closing_bet_after(current_timestamp)}s for: {ws.events_predictions[event_id]}", extra={"emoji": ":alarm_clock:"}, ) else: