diff --git a/README.md b/README.md index 50c77646..d07f0860 100644 --- a/README.md +++ b/README.md @@ -134,19 +134,19 @@ For the bet system the script use Selenium. Could be usefull understand how to M Outcome1(NO (PINK) Points: 2M, Users: 146 (56.15%), Odds: 1.31 (76.34%)) Result: {'type': 'LOSE', 'won': 0} -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username, channel_id=0000000, channel_points=67247), Gained (end-start): -7838 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username, channel_id=0000000, channel_points=67247), Total points gained (after farming - before farming): -7838 %d/%m/%y %H:%M:%S - 💰 WATCH(35 times, 350 gained), CLAIM(11 times, 550 gained), PREDICTION(1 times, 6531 gained) -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username1, channel_id=0000000, channel_points=4240), Gained (end-start): 0 -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username2, channel_id=0000000, channel_points=61365), Gained (end-start): 977 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username1, channel_id=0000000, channel_points=4240), Total points gained (after farming - before farming): 0 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username2, channel_id=0000000, channel_points=61365), Total points gained (after farming - before farming): 977 %d/%m/%y %H:%M:%S - 💰 WATCH(11 times, 132 gained), REFUND(1 times, 605 gained), CLAIM(4 times, 240 gained) -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username3, channel_id=0000000, channel_points=6815), Gained (end-start): 0 -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username4, channel_id=0000000, channel_points=16386), Gained (end-start): 0 -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username5, channel_id=0000000, channel_points=25960), Gained (end-start): 1680 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username3, channel_id=0000000, channel_points=6815), Total points gained (after farming - before farming): 0 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username4, channel_id=0000000, channel_points=16386), Total points gained (after farming - before farming): 0 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username5, channel_id=0000000, channel_points=25960), Total points gained (after farming - before farming): 1680 %d/%m/%y %H:%M:%S - 💰 WATCH(53 times, 530 gained), CLAIM(17 times, 850 gained) -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username6, channel_id=0000000, channel_points=9430), Gained (end-start): 1120 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username6, channel_id=0000000, channel_points=9430), Total points gained (after farming - before farming): 1120 %d/%m/%y %H:%M:%S - 💰 WATCH(42 times, 420 gained), WATCH_STREAK(1 times, 450 gained), CLAIM(14 times, 700 gained) -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username7, channel_id=0000000, channel_points=2380), Gained (end-start): 0 -%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username8, channel_id=0000000, channel_points=10230), Gained (end-start): 0 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username7, channel_id=0000000, channel_points=2380), Total points gained (after farming - before farming): 0 +%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username8, channel_id=0000000, channel_points=10230), Total points gained (after farming - before farming): 0 ``` ## How to use: diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index 75a91fda..f5084152 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -22,7 +22,7 @@ TwitchBrowser, ) from TwitchChannelPointsMiner.classes.WebSocketsPool import WebSocketsPool -from TwitchChannelPointsMiner.utils import get_user_agent +from TwitchChannelPointsMiner.utils import _millify, get_user_agent # Suppress warning for urllib3.connectionpool (selenium close connection) # Suppress also the selenium logger please @@ -103,7 +103,7 @@ def run(self, streamers: list = [], followers=False): # Append at the end with lowest priority followers_array = self.twitch.get_followers() logger.info( - f"Load {len(followers_array)} followers from your profile!", + f"Loading {len(followers_array)} followers from your profile!", extra={"emoji": ":clipboard:"}, ) streamers += [fw for fw in followers_array if fw not in streamers] @@ -257,7 +257,7 @@ def __print_report(self): for streamer_index in range(0, len(self.streamers)): self.streamers[streamer_index].set_less_printing(False) logger.info( - f"{self.streamers[streamer_index]}, Total Points Gained (after farming - before farming): {self.streamers[streamer_index].channel_points - self.original_streamers[streamer_index].channel_points}", + f"{self.streamers[streamer_index]}, Total points gained (after farming - before farming): {_millify(self.streamers[streamer_index].channel_points - self.original_streamers[streamer_index].channel_points)}", extra={"emoji": ":robot:"}, ) if self.streamers[streamer_index].history != {}: diff --git a/TwitchChannelPointsMiner/classes/Bet.py b/TwitchChannelPointsMiner/classes/Bet.py index 02ccdf68..26f24120 100644 --- a/TwitchChannelPointsMiner/classes/Bet.py +++ b/TwitchChannelPointsMiner/classes/Bet.py @@ -2,9 +2,7 @@ import logging from enum import Enum, auto -from millify import millify - -from TwitchChannelPointsMiner.utils import float_round +from TwitchChannelPointsMiner.utils import _millify, float_round logger = logging.getLogger(__name__) @@ -74,11 +72,11 @@ def update_outcomes(self, outcomes): self.__clear_outcomes() def __repr__(self): - return f"Bet(TotalUsers={millify(self.total_users)}, TotalPoints={millify(self.total_points)}), Decision={self.decision})\n\t\tOutcome0({self.get_outcome(0)})\n\t\tOutcome1({self.get_outcome(1)})" + return f"Bet(TotalUsers={_millify(self.total_users)}, TotalPoints={_millify(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] - return f"{outcome['title']} ({outcome['color']}), Points: {millify(outcome['total_points'])}, Users: {millify(outcome['total_users'])} ({outcome['percentage_users']}%), Odds: {outcome['odds']} ({outcome['odds_percentage']}%)" + return f"{outcome['title']} ({outcome['color']}), Points: {_millify(outcome['total_points'])}, Users: {_millify(outcome['total_users'])} ({outcome['percentage_users']}%), Odds: {outcome['odds']} ({outcome['odds_percentage']}%)" def __clear_outcomes(self): for index in range(0, len(self.outcomes)): diff --git a/TwitchChannelPointsMiner/classes/Streamer.py b/TwitchChannelPointsMiner/classes/Streamer.py index d07c11e0..40570734 100644 --- a/TwitchChannelPointsMiner/classes/Streamer.py +++ b/TwitchChannelPointsMiner/classes/Streamer.py @@ -1,10 +1,9 @@ import logging import time -from millify import prettify - from TwitchChannelPointsMiner.classes.Stream import Stream from TwitchChannelPointsMiner.constants.twitch import URL +from TwitchChannelPointsMiner.utils import _millify logger = logging.getLogger(__name__) @@ -33,16 +32,16 @@ def __init__(self, username, channel_id, less_printing: bool = False): def __repr__(self): return ( - f"{self.username} ({prettify(self.channel_points, '.')} points)" + f"{self.username} ({_millify(self.channel_points)} points)" if self.less_printing is True - else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={prettify(self.channel_points, '.')})" + else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})" ) def __str__(self): return ( - f"{self.username} ({prettify(self.channel_points, '.')} points)" + f"{self.username} ({_millify(self.channel_points)} points)" if self.less_printing is True - else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={prettify(self.channel_points, '.')})" + else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})" ) def set_offline(self): @@ -63,7 +62,7 @@ def set_online(self): def print_history(self): return ", ".join( [ - f"{key}({self.history[key]['counter']} times, {prettify(self.history[key]['amount'], '.')} gained)" + f"{key}({self.history[key]['counter']} times, {_millify(self.history[key]['amount'])} gained)" for key in self.history ] ) diff --git a/TwitchChannelPointsMiner/classes/TwitchBrowser.py b/TwitchChannelPointsMiner/classes/TwitchBrowser.py index 32ef8dd2..19ec4400 100644 --- a/TwitchChannelPointsMiner/classes/TwitchBrowser.py +++ b/TwitchChannelPointsMiner/classes/TwitchBrowser.py @@ -6,7 +6,6 @@ from enum import Enum, auto from pathlib import Path -from millify import prettify from selenium import webdriver from selenium.common.exceptions import JavascriptException, TimeoutException from selenium.webdriver.common.action_chains import ActionChains @@ -17,7 +16,7 @@ from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction from TwitchChannelPointsMiner.constants.browser import Javascript, Selectors from TwitchChannelPointsMiner.constants.twitch import URL -from TwitchChannelPointsMiner.utils import bet_condition, get_user_agent +from TwitchChannelPointsMiner.utils import _millify, bet_condition, get_user_agent logger = logging.getLogger(__name__) @@ -339,7 +338,7 @@ def place_bet(self, event: EventPrediction): try: logger.info( - f"Going to write: {prettify(decision['amount'], '.')} channel points on input {decision['choice']}", + f"Going to write: {_millify(decision['amount'])} channel points on input {decision['choice']}", extra={"emoji": ":wrench:"}, ) if ( diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index ef59dd41..bbb5d36f 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -5,7 +5,6 @@ import time from dateutil import parser -from millify import millify from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction from TwitchChannelPointsMiner.classes.Exceptions import TimeBasedDropNotFound @@ -14,6 +13,7 @@ from TwitchChannelPointsMiner.classes.TwitchWebSocket import TwitchWebSocket from TwitchChannelPointsMiner.constants.twitch import WEBSOCKET from TwitchChannelPointsMiner.utils import ( + _millify, bet_condition, calculate_start_after, get_streamer_index, @@ -268,7 +268,7 @@ def on_message(ws, message): if message.type == "prediction-result": event_result = message.data["prediction"]["result"] logger.info( - f"{ws.events_predictions[event_id]} - Result: {event_result['type']}, Points won: {millify(event_result['points_won']) if event_result['points_won'] else 0}", + f"{ws.events_predictions[event_id]} - Result: {event_result['type']}, Points won: {_millify(event_result['points_won']) if event_result['points_won'] else 0}", extra={"emoji": ":bar_chart:"}, ) points_won = ( diff --git a/TwitchChannelPointsMiner/utils.py b/TwitchChannelPointsMiner/utils.py index f06c1115..b94d0c14 100644 --- a/TwitchChannelPointsMiner/utils.py +++ b/TwitchChannelPointsMiner/utils.py @@ -4,9 +4,15 @@ from datetime import datetime, timezone from random import randrange +from millify import millify + from TwitchChannelPointsMiner.constants.browser import USER_AGENTS +def _millify(input, precision=2): + return millify(input, precision) + + def get_streamer_index(streamers: list, channel_id) -> int: try: return next( diff --git a/example.py b/example.py index 65a4e386..1f499e51 100644 --- a/example.py +++ b/example.py @@ -36,4 +36,4 @@ twitch_miner.mine( ["streamer1", "streamer2"], # Array of streamers (order = priority) followers=False # Automatic download the list of your followers -) +) \ No newline at end of file