Skip to content

Commit

Permalink
Improve less logging option #10
Browse files Browse the repository at this point in the history
  • Loading branch information
Tkd-Alex committed Jan 22, 2021
1 parent 8780120 commit a9cf39f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion TwitchChannelPointsMiner/classes/Bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 8 additions & 4 deletions TwitchChannelPointsMiner/classes/TwitchBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 (
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion TwitchChannelPointsMiner/classes/WebSocketsPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a9cf39f

Please sign in to comment.