From 12e07547a09702852e8001ccd7c1327527d98960 Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Fri, 19 Feb 2021 16:13:42 -0300 Subject: [PATCH 01/10] Printing colorful EventPrediction results Added colorama to the requirements and made a simple code to print win results in green and lose results in red --- .../TwitchChannelPointsMiner.py | 2 ++ .../classes/WebSocketsPool.py | 20 +++++++++++++++---- requirements.txt | 1 + 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index 1ef6ab1..cf1417f 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -28,6 +28,8 @@ from TwitchChannelPointsMiner.utils import ( internet_connection_available, set_default_settings, ) +from colorama import init +init() # Suppress: # - chardet.charsetprober - [feed] diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 67349b0..7cfc8ee 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -4,6 +4,7 @@ import random import threading import time +from colorama import Fore, Style from dateutil import parser from TwitchChannelPointsMiner.classes.entities.EventPrediction import EventPrediction @@ -307,10 +308,21 @@ class WebSocketsPool: else 0 ) points_prefix = "+" if points_gained >= 0 else "" - logger.info( - f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}", - extra={"emoji": ":bar_chart:"}, - ) + if result_type == "WIN": + logger.info( + Fore.GREEN + + f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}" + + Style.RESET_ALL, + extra={"emoji": ":bar_chart:"}, + ) + else: + logger.info( + Fore.RED + + f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}" + + Style.RESET_ALL, + extra={"emoji": ":bar_chart:"}, + ) + ws.events_predictions[event_id].final_result = { "type": event_result["type"], "points_won": points_won, diff --git a/requirements.txt b/requirements.txt index 46f7d58..99b7cee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ python-dateutil emoji millify pre-commit +colorama From 23232ed2c1e1f431e25bfa2a0683009d3151e3e9 Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Sat, 20 Feb 2021 20:35:08 -0300 Subject: [PATCH 02/10] Adding color to the formatter --- .../classes/WebSocketsPool.py | 21 +++++-------------- TwitchChannelPointsMiner/logger.py | 17 +++++++++++---- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 6e4fa39..b8cc0bb 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -4,7 +4,7 @@ import random import threading import time -from colorama import Fore, Style +from colorama import Fore from dateutil import parser from TwitchChannelPointsMiner.classes.entities.EventPrediction import EventPrediction @@ -308,21 +308,10 @@ class WebSocketsPool: else 0 ) points_prefix = "+" if points_gained >= 0 else "" - if result_type == "WIN": - logger.info( - Fore.GREEN + - f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}" + - Style.RESET_ALL, - extra={"emoji": ":bar_chart:"}, - ) - else: - logger.info( - Fore.RED + - f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}" + - Style.RESET_ALL, - extra={"emoji": ":bar_chart:"}, - ) - + logger.info( + f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}", + extra={"emoji": ":bar_chart:", "color": Fore.GREEN if result_type == "WIN" else Fore.RED}, + ) ws.events_predictions[event_id].final_result = { "type": event_result["type"], "points_won": points_won, diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 26321ac..5c87bf6 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -5,13 +5,15 @@ from datetime import datetime from pathlib import Path import emoji +from colorama import Style from TwitchChannelPointsMiner.utils import remove_emoji -class EmojiFormatter(logging.Formatter): - def __init__(self, *, fmt, datefmt=None, print_emoji=True): +class GlobalFormatter(logging.Formatter): + def __init__(self, *, fmt, datefmt=None, print_emoji=True, print_colored=False): self.print_emoji = print_emoji + self.print_colored = print_colored logging.Formatter.__init__(self, fmt=fmt, datefmt=datefmt) def format(self, record): @@ -36,6 +38,9 @@ class EmojiFormatter(logging.Formatter): # Full remove using a method from utils. record.msg = remove_emoji(record.msg) + if hasattr(record, "color"): + record.msg = f"{record.color}{record.msg}{Style.RESET_ALL}" + return super().format(record) @@ -47,12 +52,14 @@ class LoggerSettings: console_level: int = logging.INFO, file_level: int = logging.DEBUG, emoji: bool = platform.system() != "Windows", + colored: bool = False, ): self.save = save self.less = less self.console_level = console_level self.file_level = file_level self.emoji = emoji + self.colored = colored def configure_loggers(username, settings): @@ -62,7 +69,7 @@ def configure_loggers(username, settings): console_handler = logging.StreamHandler() console_handler.setLevel(settings.console_level) console_handler.setFormatter( - EmojiFormatter( + GlobalFormatter( fmt=( "%(asctime)s - %(levelname)s - [%(funcName)s]: %(message)s" if settings.less is False @@ -72,6 +79,7 @@ def configure_loggers(username, settings): "%d/%m/%y %H:%M:%S" if settings.less is False else "%d/%m %H:%M:%S" ), print_emoji=settings.emoji, + print_colored=settings.colored, ) ) root_logger.addHandler(console_handler) @@ -85,10 +93,11 @@ def configure_loggers(username, settings): ) file_handler = logging.FileHandler(logs_file, "w", "utf-8") file_handler.setFormatter( - EmojiFormatter( + GlobalFormatter( fmt="%(asctime)s - %(levelname)s - %(name)s - [%(funcName)s]: %(message)s", datefmt="%d/%m/%y %H:%M:%S", print_emoji=settings.emoji, + print_colored=settings.colored, ) ) file_handler.setLevel(settings.file_level) From 47e620004085c7880b16a9675302dd4e306491dd Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Sat, 20 Feb 2021 20:54:32 -0300 Subject: [PATCH 03/10] Fixing colored perms and updating docs --- README.md | 8 +++++--- TwitchChannelPointsMiner/logger.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fcd4363..41c268f 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,8 @@ twitch_miner = TwitchChannelPointsMiner( console_level=logging.INFO, # Level of logs - use logging.DEBUG for more info) file_level=logging.DEBUG, # Level of logs - If you think the log file it's too big, use logging.INFO emoji=True, # On Windows, we have a problem printing emoji. Set to false if you have a problem - less=False # If you think that the logs are too verbose, set this to True + less=False, # If you think that the logs are too verbose, set this to True + colored=True # If you want to print colored text ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction @@ -249,8 +250,9 @@ Make sure to write the streamers array in order of priority from left to right. | `save` | bool | True | If you want to save logs in file (suggested) | | `less` | bool | False | Reduce the logging format and message verbosity [#10](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/10) | | `console_level` | level | logging.INFO | Level of logs in terminal - Use logging.DEBUG for more helpful messages. | -| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO | -| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem | +| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO | +| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem | +| `colored` | bool | True | If you want to print colored text | ### StreamerSettings | Key | Type | Default | Description | |-------------------- |------------- |-------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 5c87bf6..7d381e2 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -38,7 +38,7 @@ class GlobalFormatter(logging.Formatter): # Full remove using a method from utils. record.msg = remove_emoji(record.msg) - if hasattr(record, "color"): + if self.print_colored and hasattr(record, "color"): record.msg = f"{record.color}{record.msg}{Style.RESET_ALL}" return super().format(record) From 60d0ccbb0394d5022509ef93288f6a93419728da Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Sat, 20 Feb 2021 22:47:01 -0300 Subject: [PATCH 04/10] Fixing lint warnings --- TwitchChannelPointsMiner/TwitchChannelPointsMiner.py | 1 + TwitchChannelPointsMiner/classes/WebSocketsPool.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index 294656f..df422f8 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -29,6 +29,7 @@ from TwitchChannelPointsMiner.utils import ( set_default_settings, ) from colorama import init + init() # Suppress: diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index b8cc0bb..283dba6 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -310,7 +310,12 @@ class WebSocketsPool: points_prefix = "+" if points_gained >= 0 else "" logger.info( f"{ws.events_predictions[event_id]} - Result: {result_type}, Gained: {points_prefix}{_millify(points_gained)}", - extra={"emoji": ":bar_chart:", "color": Fore.GREEN if result_type == "WIN" else Fore.RED}, + extra={ + "emoji": ":bar_chart:", + "color": Fore.GREEN + if result_type == "WIN" + else Fore.RED, + } ) ws.events_predictions[event_id].final_result = { "type": event_result["type"], From 7abab21c244a2b4f1444590048194d11bb91f401 Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Sat, 20 Feb 2021 22:48:39 -0300 Subject: [PATCH 05/10] Fixing lint warnings --- TwitchChannelPointsMiner/classes/WebSocketsPool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 283dba6..769a01a 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -315,7 +315,7 @@ class WebSocketsPool: "color": Fore.GREEN if result_type == "WIN" else Fore.RED, - } + }, ) ws.events_predictions[event_id].final_result = { "type": event_result["type"], From 7182d8af43bfb8f350cbd74606829c201e3448ce Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Mon, 22 Feb 2021 13:03:19 +0100 Subject: [PATCH 06/10] init colorama inside configure_loggers - Remove GlobalFormatter for fileHandler. Add before the file logger and then console logger. --- .../TwitchChannelPointsMiner.py | 3 --- TwitchChannelPointsMiner/logger.py | 16 ++++++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index df422f8..156bdad 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -28,9 +28,6 @@ from TwitchChannelPointsMiner.utils import ( internet_connection_available, set_default_settings, ) -from colorama import init - -init() # Suppress: # - chardet.charsetprober - [feed] diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 7d381e2..3233bb5 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -5,7 +5,7 @@ from datetime import datetime from pathlib import Path import emoji -from colorama import Style +from colorama import Style, init from TwitchChannelPointsMiner.utils import remove_emoji @@ -63,6 +63,9 @@ class LoggerSettings: def configure_loggers(username, settings): + if settings.colored is True: + init() + root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) @@ -82,7 +85,6 @@ def configure_loggers(username, settings): print_colored=settings.colored, ) ) - root_logger.addHandler(console_handler) if settings.save is True: logs_path = os.path.join(Path().absolute(), "logs") @@ -93,14 +95,16 @@ def configure_loggers(username, settings): ) file_handler = logging.FileHandler(logs_file, "w", "utf-8") file_handler.setFormatter( - GlobalFormatter( + logging.Formatter( fmt="%(asctime)s - %(levelname)s - %(name)s - [%(funcName)s]: %(message)s", datefmt="%d/%m/%y %H:%M:%S", - print_emoji=settings.emoji, - print_colored=settings.colored, ) ) file_handler.setLevel(settings.file_level) + root_logger.addHandler(file_handler) + root_logger.addHandler(console_handler) return logs_file - return None + else: + root_logger.addHandler(console_handler) + return None From 7387357662acadd0fe01bd01f603bf0c099184b3 Mon Sep 17 00:00:00 2001 From: TipicoDev <8689989+TipicoDev@users.noreply.github.com> Date: Thu, 25 Feb 2021 08:18:25 -0300 Subject: [PATCH 07/10] Conditioning colors initializer --- TwitchChannelPointsMiner/TwitchChannelPointsMiner.py | 3 --- TwitchChannelPointsMiner/logger.py | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index df422f8..156bdad 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -28,9 +28,6 @@ from TwitchChannelPointsMiner.utils import ( internet_connection_available, set_default_settings, ) -from colorama import init - -init() # Suppress: # - chardet.charsetprober - [feed] diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 7d381e2..60e5c8f 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -5,7 +5,7 @@ from datetime import datetime from pathlib import Path import emoji -from colorama import Style +from colorama import Style, init from TwitchChannelPointsMiner.utils import remove_emoji @@ -63,6 +63,9 @@ class LoggerSettings: def configure_loggers(username, settings): + if settings.colored is True: + init() + root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) From 774280abe53b69b3c0369bdbee5002799badd508 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Thu, 25 Feb 2021 14:10:26 +0100 Subject: [PATCH 08/10] Create customizable ColorPalette for terminal message --- README.md | 76 ++++++++++++---- TwitchChannelPointsMiner/classes/Twitch.py | 26 ++++-- .../classes/WebSocketsPool.py | 17 ++-- .../classes/entities/Streamer.py | 16 +++- TwitchChannelPointsMiner/logger.py | 57 +++++++++++- example.py | 11 ++- settings.json | 86 +++++++++++++++++++ 7 files changed, 253 insertions(+), 36 deletions(-) create mode 100644 settings.json diff --git a/README.md b/README.md index 1c15683..15c1707 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ If you have any issues or you want to contribute, you are welcome! But please be ## Main differences from the original repository: -- Improve the logging +- Improve the logging - Emoji, colors, file and soo on - Final report with all the data - Rewrite the entire code using classe instead of module with global variables - Automatic download the follower's list and use it as input @@ -166,8 +166,9 @@ No browser needed. [#41](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner # -*- coding: utf-8 -*- import logging +from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner -from TwitchChannelPointsMiner.logger import LoggerSettings +from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Settings import Priority from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -187,7 +188,12 @@ twitch_miner = TwitchChannelPointsMiner( file_level=logging.DEBUG, # Level of logs - If you think the log file it's too big, use logging.INFO emoji=True, # On Windows, we have a problem printing emoji. Set to false if you have a problem less=False, # If you think that the logs are too verbose, set this to True - colored=True # If you want to print colored text + colored=True, # If you want to print colored text + color_palette=ColorPalette( # You can also create a custom palette color (for the common message). + STREAMER_online="GREEN", # Don't worry about lower/upper case the script will be parse all the values. + streamer_offline="red", # Read more in README.md + BET_wiN=Fore.MAGENTA # Color allowed are: [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET]. + ) ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction @@ -262,22 +268,58 @@ Available values are the following: You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCENDING` in the same settings doesn't make sense. ### LoggerSettings -| Key | Type | Default | Description | -|----------------- |----------------- |-------------------------------- |---------------------------------------------------------------------------------------------------------------------------- | -| `save` | bool | True | If you want to save logs in file (suggested) | -| `less` | bool | False | Reduce the logging format and message verbosity [#10](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/10) | -| `console_level` | level | logging.INFO | Level of logs in terminal - Use logging.DEBUG for more helpful messages. | -| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO | -| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem | -| `colored` | bool | True | If you want to print colored text | +| Key | Type | Default | Description | +|----------------- |----------------- |-------------------------------------------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `save` | bool | True | If you want to save logs in file (suggested) | +| `less` | bool | False | Reduce the logging format and message verbosity [#10](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/10) | +| `console_level` | level | logging.INFO | Level of logs in terminal - Use logging.DEBUG for more helpful messages. | +| `file_level` | level | logging.DEBUG | Level of logs in file save - If you think the log file it's too big, use logging.INFO | +| `emoji` | bool | For Windows is False else True | On Windows, we have a problem printing emoji. Set to false if you have a problem | +| `colored` | bool | True | If you want to print colored text [#45](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/45) [#82](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/82) | +| `color_palette` | ColorPalette | All messages are Fore.RESET except WIN and LOSE bet (GREEN and RED) | Create your custom color palette. Read more above. | + +#### Color Palette +Now you can customize the color of the terminal message. We have created a default ColorPalette that provide all the message with `DEFAULT (RESET)` color and the `BET_WIN` and `BET_LOSE` message `GREEN` and `RED` respectively. +Currently you can only change the following types of messages: + - `STREAMER_ONLINE` + - `STREAMER_OFFLINE` + - `GAIN_FOR_RAID` + - `GAIN_FOR_CLAIM` + - `GAIN_FOR_WATCH` + - `BET_WIN` + - `BET_LOSE` + - `BET_REFUND` + - `BET_FILTERS` + - `BET_GENERAL` + - `BET_FAILED` + +The colors allowed are all the Fore color from Colorama: `BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.` +The script was developed to handle all the human error, lower-case upper case and more, but I want to suggest using the following code-style +```python +from colorama import Fore +ColorPalette( + "STREAMER_ONLINE" = Fore.GREEN, + "STREAMER_OFFLINE" = Fore.RED, + "GAIN_FOR_RAID" = Fore.YELLOW, + "GAIN_FOR_CLAIM" = Fore.YELLOW, + "GAIN_FOR_WATCH" = Fore.YELLOW, + "BET_WIN" = Fore.GREEN, + "BET_LOSE" = Fore.RED, + "BET_REFUND" = Fore.RESET, + "BET_FILTERS" = Fore.MAGENTA, + "BET_GENERAL" = Fore.BLUE, + "BET_FAILED" = Fore.RED, +) +``` + ### StreamerSettings -| Key | Type | Default | Description | -|-------------------- |------------- |-------------------------------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `make_predictions` | bool | True | Choose if you want to make predictions / bet or not | -| `follow_raid` | bool | True | Choose if you want to follow raid +250 points | +| Key | Type | Default | Description | +|-------------------- |------------- |-------------------------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `make_predictions` | bool | True | Choose if you want to make predictions / bet or not | +| `follow_raid` | bool | True | Choose if you want to follow raid +250 points | | `claim_drops` | bool | True | If this value is True, the script will increase the watch-time for the current game. With this, you are able to claim the drops from Twitch Inventory [#21](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/21) | -| `watch_streak` | bool | True | Choose if you want to change a priority for these streamers and try to catch the Watch Streak event [#11](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/11) | -| `bet` | BetSettings | | Rules to follow for the bet | +| `watch_streak` | bool | True | Choose if you want to change a priority for these streamers and try to catch the Watch Streak event [#11](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/11) | +| `bet` | BetSettings | | Rules to follow for the bet | ### BetSettings | Key | Type | Default | Description | |-------------------- |----------------- |--------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index d651c72..08ce5ad 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -392,23 +392,36 @@ class Twitch(object): logger.info( f"Going to complete bet for {event}", - extra={"emoji": ":four_leaf_clover:"}, + extra={ + "emoji": ":four_leaf_clover:", + "color": Settings.logger.color_palette.BET_GENERAL, + }, ) if event.status == "ACTIVE": skip, compared_value = event.bet.skip() if skip is True: logger.info( - f"Skip betting for the event {event}", extra={"emoji": ":pushpin:"} + f"Skip betting for the event {event}", + extra={ + "emoji": ":pushpin:", + "color": Settings.logger.color_palette.BET_FILTERS, + }, ) logger.info( f"Skip settings {event.bet.settings.filter_condition}, current value is: {compared_value}", - extra={"emoji": ":pushpin:"}, + extra={ + "emoji": ":pushpin:", + "color": Settings.logger.color_palette.BET_FILTERS, + }, ) else: if decision["amount"] >= 10: logger.info( f"Place {_millify(decision['amount'])} channel points on: {event.bet.get_outcome(selector_index)}", - extra={"emoji": ":four_leaf_clover:"}, + extra={ + "emoji": ":four_leaf_clover:", + "color": Settings.logger.color_palette.BET_GENERAL, + }, ) json_data = copy.deepcopy(GQLOperations.MakePrediction) @@ -424,7 +437,10 @@ class Twitch(object): else: logger.info( f"Oh no! The event is not active anymore! Current status: {event.status}", - extra={"emoji": ":disappointed_relieved:"}, + extra={ + "emoji": ":disappointed_relieved:", + "color": Settings.logger.color_palette.BET_FAILED, + }, ) def claim_bonus(self, streamer, claim_id): diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 97c2146..5fa6697 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -4,14 +4,12 @@ import random import threading import time -from colorama import Fore from dateutil import parser from TwitchChannelPointsMiner.classes.entities.EventPrediction import EventPrediction from TwitchChannelPointsMiner.classes.entities.Message import Message from TwitchChannelPointsMiner.classes.entities.Raid import Raid - -# from TwitchChannelPointsMiner.classes.Exceptions import TimeBasedDropNotFound +from TwitchChannelPointsMiner.classes.Settings import Settings from TwitchChannelPointsMiner.classes.TwitchWebSocket import TwitchWebSocket from TwitchChannelPointsMiner.constants import WEBSOCKET from TwitchChannelPointsMiner.utils import ( @@ -186,7 +184,12 @@ class WebSocketsPool: ws.streamers[streamer_index].channel_points = balance logger.info( f"+{earned} → {ws.streamers[streamer_index]} - Reason: {reason_code}.", - extra={"emoji": ":rocket:"}, + extra={ + "emoji": ":rocket:", + "color": Settings.logger.color_palette.get( + f"GAIN_FOR_{reason_code}" + ), + }, ) ws.streamers[streamer_index].update_history( reason_code, earned @@ -322,9 +325,9 @@ class WebSocketsPool: f"{ws.events_predictions[event_id]} - Result: {result_type}, {action}: {points_prefix}{_millify(points_gained)}", extra={ "emoji": ":bar_chart:", - "color": Fore.GREEN - if result_type == "WIN" - else Fore.RED, + "color": Settings.logger.color_palette.get( + f"BET_{result_type}" + ), }, ) ws.events_predictions[event_id].final_result = { diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index 3779669..074e7ff 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -96,7 +96,13 @@ class Streamer(object): self.offline_at = time.time() self.is_online = False - logger.info(f"{self} is Offline!", extra={"emoji": ":sleeping:"}) + logger.info( + f"{self} is Offline!", + extra={ + "emoji": ":sleeping:", + "color": Settings.logger.color_palette.STREAMER_OFFLINE, + }, + ) def set_online(self): if self.is_online is False: @@ -104,7 +110,13 @@ class Streamer(object): self.is_online = True self.stream.init_watch_streak() - logger.info(f"{self} is Online!", extra={"emoji": ":partying_face:"}) + logger.info( + f"{self} is Online!", + extra={ + "emoji": ":partying_face:", + "color": Settings.logger.color_palette.STREAMER_ONLINE, + }, + ) def print_history(self): return ", ".join( diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index 3233bb5..a3a12b9 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -5,7 +5,7 @@ from datetime import datetime from pathlib import Path import emoji -from colorama import Style, init +from colorama import Fore, init from TwitchChannelPointsMiner.utils import remove_emoji @@ -39,11 +39,60 @@ class GlobalFormatter(logging.Formatter): record.msg = remove_emoji(record.msg) if self.print_colored and hasattr(record, "color"): - record.msg = f"{record.color}{record.msg}{Style.RESET_ALL}" + record.msg = f"{record.color}{record.msg}" return super().format(record) +# Fore: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET. +class ColorPalette(object): + STREAMER_ONLINE = Fore.RESET + STREAMER_OFFLINE = Fore.RESET + + GAIN_FOR_RAID = Fore.RESET + GAIN_FOR_CLAIM = Fore.RESET + GAIN_FOR_WATCH = Fore.RESET + + BET_WIN = Fore.GREEN + BET_LOSE = Fore.RED + BET_REFUND = Fore.RESET + BET_FILTERS = Fore.RESET + BET_GENERAL = Fore.RESET + BET_FAILED = Fore.RESET + + def __init__(self, **kwargs): + for k in kwargs: + if getattr(self, k.upper()) is not None: + if kwargs[k] in [ + Fore.BLACK, + Fore.RED, + Fore.GREEN, + Fore.YELLOW, + Fore.BLUE, + Fore.MAGENTA, + Fore.CYAN, + Fore.WHITE, + Fore.RESET, + ]: + setattr(self, k.upper(), kwargs[k]) + elif kwargs[k].upper() in [ + "BLACK", + "RED", + "GREEN", + "YELLOW", + "BLUE", + "MAGENTA", + "CYAN", + "WHITE", + "RESET", + ]: + setattr(self, k.upper(), getattr(Fore, kwargs[k].upper())) + + def get(self, key): + color = getattr(self, key.upper()) + return Fore.RESET if color is None else color + + class LoggerSettings: def __init__( self, @@ -53,6 +102,7 @@ class LoggerSettings: file_level: int = logging.DEBUG, emoji: bool = platform.system() != "Windows", colored: bool = False, + color_palette: ColorPalette = ColorPalette(), ): self.save = save self.less = less @@ -60,11 +110,12 @@ class LoggerSettings: self.file_level = file_level self.emoji = emoji self.colored = colored + self.color_palette = color_palette def configure_loggers(username, settings): if settings.colored is True: - init() + init(autoreset=True) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) diff --git a/example.py b/example.py index a574194..032f010 100644 --- a/example.py +++ b/example.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- import logging +from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner -from TwitchChannelPointsMiner.logger import LoggerSettings +from TwitchChannelPointsMiner.logger import LoggerSettings, ColorPalette from TwitchChannelPointsMiner.classes.Settings import Priority from TwitchChannelPointsMiner.classes.entities.Bet import Strategy, BetSettings, Condition, OutcomeKeys, FilterCondition from TwitchChannelPointsMiner.classes.entities.Streamer import Streamer, StreamerSettings @@ -21,7 +22,13 @@ twitch_miner = TwitchChannelPointsMiner( console_level=logging.INFO, # Level of logs - use logging.DEBUG for more info) file_level=logging.DEBUG, # Level of logs - If you think the log file it's too big, use logging.INFO emoji=True, # On Windows, we have a problem printing emoji. Set to false if you have a problem - less=False # If you think that the logs are too verbose, set this to True + less=False, # If you think that the logs are too verbose, set this to True + colored=True, # If you want to print colored text + color_palette=ColorPalette( # You can also create a custom palette color (for the common message). + STREAMER_online="GREEN", # Don't worry about lower/upper case the script will be parse all the values. + streamer_offline="red", # Read more in README.md + BET_wiN=Fore.MAGENTA # Color allowed are: [BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET]. + ) ), streamer_settings=StreamerSettings( make_predictions=True, # If you want to Bet / Make prediction diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..8c74855 --- /dev/null +++ b/settings.json @@ -0,0 +1,86 @@ +[ + { + "settings": null, + "username": "r_eqxxx" + }, + { + "settings": null, + "username": "vhauss" + }, + { + "settings": null, + "username": "carriedbyoujua" + }, + { + "settings": null, + "username": "robertcrg" + }, + { + "settings": null, + "username": "blu3berrycupcake" + }, + { + "settings": null, + "username": "brbteabreak" + }, + { + "settings": null, + "username": "nut9tv" + }, + { + "settings": null, + "username": "joaoboavista" + }, + { + "settings": null, + "username": "hyeaga" + }, + { + "settings": null, + "username": "chaosmachinegr" + }, + { + "settings": null, + "username": "malteseknight_" + }, + { + "settings": null, + "username": "daniel_rusev" + }, + { + "settings": null, + "username": "serwinterofficial" + }, + { + "settings": null, + "username": "shadowfrax" + }, + { + "settings": null, + "username": "boxbox" + }, + { + "settings": null, + "username": "ash_on_lol" + }, + { + "settings": null, + "username": "dyannatv" + }, + { + "settings": null, + "username": "mammoth" + }, + { + "settings": null, + "username": "bchillz" + }, + { + "settings": null, + "username": "buddha" + }, + { + "settings": null, + "username": "trausi" + } +] From ec58ce147b7c3bcb61ce3fc4a19850661d92e954 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Thu, 25 Feb 2021 16:03:37 +0100 Subject: [PATCH 09/10] ops, fix missing key in class --- TwitchChannelPointsMiner/logger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index a3a12b9..fdeab74 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -62,7 +62,7 @@ class ColorPalette(object): def __init__(self, **kwargs): for k in kwargs: - if getattr(self, k.upper()) is not None: + if k.upper() in dir(self) and getattr(self, k.upper()) is not None: if kwargs[k] in [ Fore.BLACK, Fore.RED, @@ -89,7 +89,7 @@ class ColorPalette(object): setattr(self, k.upper(), getattr(Fore, kwargs[k].upper())) def get(self, key): - color = getattr(self, key.upper()) + color = getattr(self, key.upper()) if key.upper() in dir(self) else None return Fore.RESET if color is None else color From 41ac1b52c58f85931852de37ae25057ca461aa09 Mon Sep 17 00:00:00 2001 From: Alessandro Maggio Date: Fri, 26 Feb 2021 12:13:53 +0100 Subject: [PATCH 10/10] Dedicated color also for: BET_START - ' Place the bet after: 55.39s for: EventPrediction ' --- README.md | 1 + TwitchChannelPointsMiner/classes/WebSocketsPool.py | 5 ++++- TwitchChannelPointsMiner/logger.py | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15c1707..0bf426f 100644 --- a/README.md +++ b/README.md @@ -292,6 +292,7 @@ Currently you can only change the following types of messages: - `BET_FILTERS` - `BET_GENERAL` - `BET_FAILED` + - `BET_START` The colors allowed are all the Fore color from Colorama: `BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE, RESET.` The script was developed to handle all the human error, lower-case upper case and more, but I want to suggest using the following code-style diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index 5fa6697..2e5e25f 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -272,7 +272,10 @@ class WebSocketsPool: logger.info( f"Place the bet after: {start_after}s for: {ws.events_predictions[event_id]}", - extra={"emoji": ":alarm_clock:"}, + extra={ + "emoji": ":alarm_clock:", + "color": Settings.logger.color_palette.BET_START, + }, ) elif ( diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index fdeab74..db23266 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -59,6 +59,7 @@ class ColorPalette(object): BET_FILTERS = Fore.RESET BET_GENERAL = Fore.RESET BET_FAILED = Fore.RESET + BET_START = Fore.RESET def __init__(self, **kwargs): for k in kwargs: