From 51c0603732f466a5a3c0d046471528fa5360a0bb Mon Sep 17 00:00:00 2001 From: Klaro <8fv.dev@gmail.com> Date: Thu, 6 Feb 2025 17:10:18 +0100 Subject: [PATCH 01/13] Update project structure and improve logging features - Added main.py as the entry point for the application. - Updated .gitignore to exclude config.json and VSCode settings. - Changed launch configuration to use main.py. - Modified error messages to reference config.json instead of run.py. - Enhanced logging with color-coded output for better visibility. - Updated version number to 2 in __init__.py. --- .gitignore | 2 + .vscode/launch.json | 6 +- .../TwitchChannelPointsMiner.py | 8 ++- TwitchChannelPointsMiner/__init__.py | 2 +- TwitchChannelPointsMiner/classes/Twitch.py | 7 +- .../classes/entities/Streamer.py | 12 ++-- TwitchChannelPointsMiner/logger.py | 21 ++++-- main.py | 66 +++++++++++++++++++ 8 files changed, 105 insertions(+), 19 deletions(-) create mode 100644 main.py diff --git a/.gitignore b/.gitignore index 5ed07d3..6aa3390 100644 --- a/.gitignore +++ b/.gitignore @@ -143,6 +143,8 @@ cython_debug/ # Custom files run.py chromedriver* +/.vscode/settings.json +config.json # Folders cookies/* diff --git a/.vscode/launch.json b/.vscode/launch.json index be31cde..d60e5ab 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,10 +5,10 @@ "version": "0.2.0", "configurations": [ { - "name": "Python: run.py", - "type": "python", + "name": "Python: main.py", + "type": "debugpy", "request": "launch", - "program": "${cwd}/run.py", + "program": "${cwd}/main${file}.py", "console": "integratedTerminal", "justMyCode": true } diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index c1b5ddd..dd88866 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -88,7 +88,7 @@ class TwitchChannelPointsMiner: ): # Fixes TypeError: 'NoneType' object is not subscriptable if not username or username == "your-twitch-username": - logger.error("Please edit your runner file (usually run.py) and try again.") + logger.error("Please edit config.json file and try again.") logger.error("No username, exiting...") sys.exit(0) @@ -161,9 +161,9 @@ class TwitchChannelPointsMiner: current_version, github_version = check_versions() logger.info( - f"Twitch Channel Points Miner v2-{current_version} (fork by rdavydov)" + f"Twitch Channel Points Miner v2-{current_version} (fork by 0x8fv)" ) - logger.info("https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2") + logger.info("https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2") if github_version == "0.0.0": logger.error( @@ -172,6 +172,8 @@ class TwitchChannelPointsMiner: elif current_version != github_version: logger.info(f"You are running version {current_version} of this script") logger.info(f"The latest version on GitHub is {github_version}") + time.sleep(5) + sys.exit(1) for sign in [signal.SIGINT, signal.SIGSEGV, signal.SIGTERM]: signal.signal(sign, self.end) diff --git a/TwitchChannelPointsMiner/__init__.py b/TwitchChannelPointsMiner/__init__.py index 483aafb..22b3db1 100644 --- a/TwitchChannelPointsMiner/__init__.py +++ b/TwitchChannelPointsMiner/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__version__ = "1.9.9" +__version__ = "2" from .TwitchChannelPointsMiner import TwitchChannelPointsMiner __all__ = [ diff --git a/TwitchChannelPointsMiner/classes/Twitch.py b/TwitchChannelPointsMiner/classes/Twitch.py index bbfacee..d3356ea 100644 --- a/TwitchChannelPointsMiner/classes/Twitch.py +++ b/TwitchChannelPointsMiner/classes/Twitch.py @@ -18,6 +18,8 @@ import validators from pathlib import Path from secrets import choice, token_hex from typing import Dict, Any +from colorama import Fore + # from urllib.parse import quote # from base64 import urlsafe_b64decode # from datetime import datetime @@ -25,6 +27,7 @@ from typing import Dict, Any from TwitchChannelPointsMiner.classes.entities.Campaign import Campaign from TwitchChannelPointsMiner.classes.entities.CommunityGoal import CommunityGoal from TwitchChannelPointsMiner.classes.entities.Drop import Drop +from TwitchChannelPointsMiner.logger import Color256Palette from TwitchChannelPointsMiner.classes.Exceptions import ( StreamerDoesNotExistException, StreamerIsOfflineException, @@ -774,7 +777,7 @@ class Twitch(object): def claim_bonus(self, streamer, claim_id): if Settings.logger.less is False: logger.info( - f"Claiming the bonus for {streamer}!", + f"{streamer} {Color256Palette.green if Settings.logger.smart else ''}Claimed Bonus{Fore.RESET}!", extra={"emoji": ":gift:", "event": Events.BONUS_CLAIM}, ) @@ -788,7 +791,7 @@ class Twitch(object): def claim_moment(self, streamer, moment_id): if Settings.logger.less is False: logger.info( - f"Claiming the moment for {streamer}!", + f"{streamer} Claimed Moment!", extra={"emoji": ":video_camera:", "event": Events.MOMENT_CLAIM}, ) diff --git a/TwitchChannelPointsMiner/classes/entities/Streamer.py b/TwitchChannelPointsMiner/classes/entities/Streamer.py index 23ada3d..ad53dae 100644 --- a/TwitchChannelPointsMiner/classes/entities/Streamer.py +++ b/TwitchChannelPointsMiner/classes/entities/Streamer.py @@ -4,6 +4,7 @@ import os import time from datetime import datetime from threading import Lock +from colorama import Fore from TwitchChannelPointsMiner.classes.Chat import ChatPresence, ThreadChat from TwitchChannelPointsMiner.classes.entities.Bet import BetSettings, DelayMode @@ -11,6 +12,7 @@ from TwitchChannelPointsMiner.classes.entities.Stream import Stream from TwitchChannelPointsMiner.classes.Settings import Events, Settings from TwitchChannelPointsMiner.constants import URL from TwitchChannelPointsMiner.utils import _millify +from TwitchChannelPointsMiner.logger import Color256Palette logger = logging.getLogger(__name__) @@ -115,12 +117,12 @@ class Streamer(object): self.mutex = Lock() def __repr__(self): - return f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})" + return f"Streamer(username={self.username.capitalize()}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})" def __str__(self): return ( - f"{self.username} ({_millify(self.channel_points)} points)" - if Settings.logger.less + f"{self.username.capitalize()} ({Color256Palette.cyan if Settings.logger.smart else ''}{_millify(self.channel_points)}{Fore.RESET if Settings.logger.smart else ''} points)" + if Settings.logger.less or Settings.logger.smart else self.__repr__() ) @@ -132,7 +134,7 @@ class Streamer(object): self.toggle_chat() logger.info( - f"{self} is Offline!", + f"{self} is {Color256Palette.red if Settings.logger.smart else ''}Offline{Fore.RESET if Settings.logger.smart else ''}!", extra={ "emoji": ":sleeping:", "event": Events.STREAMER_OFFLINE, @@ -148,7 +150,7 @@ class Streamer(object): self.toggle_chat() logger.info( - f"{self} is Online!", + f"{self} is {Color256Palette.green if Settings.logger.smart else ''}Online{Fore.RESET if Settings.logger.smart else ''}!", extra={ "emoji": ":partying_face:", "event": Events.STREAMER_ONLINE, diff --git a/TwitchChannelPointsMiner/logger.py b/TwitchChannelPointsMiner/logger.py index ca988c0..8e81f85 100644 --- a/TwitchChannelPointsMiner/logger.py +++ b/TwitchChannelPointsMiner/logger.py @@ -62,6 +62,14 @@ class ColorPalette(object): color = getattr(self, str(key)) if str(key) in dir(self) else None return Fore.RESET if color is None else color +class Color256Palette: + red = "\033[38;5;196m" + gray = "\033[38;5;8m" + cyan = "\033[38;5;14m" + reset = "\033[38;5;254m" + purple = "\033[38;5;91m" + yellow = "\033[38;5;226m" + green = "\033[38;5;46m" class LoggerSettings: __slots__ = [ @@ -81,7 +89,8 @@ class LoggerSettings: "matrix", "pushover", "gotify", - "username" + "username", + "smart" ] def __init__( @@ -102,7 +111,8 @@ class LoggerSettings: matrix: Matrix or None = None, pushover: Pushover or None = None, gotify: Gotify or None = None, - username: str or None = None + username: str or None = None, + smart: bool = False, ): self.save = save self.less = less @@ -121,6 +131,7 @@ class LoggerSettings: self.pushover = pushover self.gotify = gotify self.username = username + self.smart = smart class FileFormatter(logging.Formatter): @@ -176,7 +187,7 @@ class GlobalFormatter(logging.Formatter): and record.emoji_is_present is False ): record.msg = emoji.emojize( - f"{record.emoji} {record.msg.strip()}", language="alias" + f"{record.emoji} {record.msg.strip()}", language="alias" ) record.emoji_is_present = True @@ -300,12 +311,12 @@ def configure_loggers(username, settings): console_handler.setFormatter( GlobalFormatter( fmt=( - "%(asctime)s - %(levelname)s - [%(funcName)s]: %(message)s" + f"[%(levelname)s] %(asctime)s: {'[%(funcName)s]: ' if not settings.smart else ''}%(message)s" if settings.less is False else "%(asctime)s - %(message)s" ), datefmt=( - "%d/%m/%y %H:%M:%S" if settings.less is False else "%d/%m %H:%M:%S" + f"{Fore.LIGHTBLACK_EX if settings.smart else ''}%H:%M:%S %d/%m/%y{Fore.RESET if settings.smart else ''}" if settings.less is False else "%H:%M:%S %d/%m" ), settings=settings, ) diff --git a/main.py b/main.py new file mode 100644 index 0000000..84576f1 --- /dev/null +++ b/main.py @@ -0,0 +1,66 @@ +import os +import json +import logging + +def clear_console(): + os.system('cls' if os.name == 'nt' else 'clear') + +def set_console_title(title): + if os.name == 'nt': + os.system(f"title {title}") + +clear_console() +set_console_title("Klaro's Twitch Miner") + +from TwitchChannelPointsMiner import TwitchChannelPointsMiner +from TwitchChannelPointsMiner.classes.Settings import FollowersOrder +from TwitchChannelPointsMiner.logger import LoggerSettings + +def load_or_create_config(file_path): + default_config = { + "username": "", + "password": "", + "streamers": [] + } + + if os.path.exists(file_path): + with open(file_path, 'r') as file: + config = json.load(file) + else: + with open(file_path, 'w') as file: + json.dump(default_config, file, indent=4) + config = default_config + + return config + +def main(): + config = load_or_create_config("config.json") + + try: + logger_settings = LoggerSettings( + save=True, + console_level=logging.INFO, + file_level=logging.DEBUG, + emoji=True, + smart=True, + ) + + twitch_miner = TwitchChannelPointsMiner( + username=config.get("username", ""), + password=config.get("password", ""), + logger_settings=logger_settings + ) + + streamers = config.get("streamers", []) + if streamers: + twitch_miner.mine(streamers) + else: + twitch_miner.mine( + followers=True, + followers_order=FollowersOrder.DESC + ) + except Exception as e: + logging.error(f"An error occurred: {e}") + +if __name__ == "__main__": + main() From e9d3c77f567915649ccac99d89975f15da87bd4f Mon Sep 17 00:00:00 2001 From: Klaro Date: Thu, 6 Feb 2025 18:58:48 +0100 Subject: [PATCH 02/13] Update repository URLs and improve import handling --- README.md | 38 ++++++++++----------------- TwitchChannelPointsMiner/constants.py | 2 +- assets/charts.html | 14 +++++----- main.py | 11 +++++--- setup.py | 2 +- 5 files changed, 31 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index d09b24e..48b220a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ ![Twitch Channel Points Miner - v2](https://raw.githubusercontent.com/rdavydov/Twitch-Channel-Points-Miner-v2/master/assets/banner.png)

-Latest Version -GitHub Repo stars +Latest Version +GitHub Repo stars GitHub Traffic GitHub Clones -License -GitHub last commit +License +GitHub last commit

@@ -18,7 +18,7 @@

-

https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2

+

https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2

**Credits** - Main idea: https://github.com/gottagofaster236/Twitch-Channel-Points-Miner @@ -62,19 +62,9 @@ Read more about the channel points [here](https://help.twitch.tv/s/article/chann ## Community If you want to help with this project, please leave a star 🌟 and share it with your friends! 😎 -If you want to offer me a coffee, I would be grateful! ❤️ - -| | | -|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------| -|Donate BTC|`bc1qq49mvgda2zw4f9kta0a85xztwuxewqwac5eckd` _(BTC)_| -|Donate DOGE|`DAKzncwKkpfPCm1xVU7u2pConpXwX7HS3D` _(DOGE)_| -|Donate via DonationAlerts|https://www.donationalerts.com/r/rdavydov| -|Donate via Boosty|https://boosty.to/rdavydov/donate| - -If you have any issues or you want to contribute, you are welcome! But please read the [CONTRIBUTING.md](https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/master/CONTRIBUTING.md) file. - ## Main differences from the original repository: +- Easyier usability especially for beginners 🚀 - Improved logging: emojis, colors, files and much more ✔️ - Final report with all the data ✔️ - Rewritten codebase now uses classes instead of modules with global variables ✔️ @@ -84,8 +74,8 @@ If you have any issues or you want to contribute, you are welcome! But please re - Placing a bet / making a prediction with your channel points [#41](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/41) ([@lay295](https://github.com/lay295)) ✔️ - Switchable analytics chart that shows the progress of your points with various annotations [#96](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/96) ✔️ - Joining the IRC Chat to increase the watch time and get StreamElements points [#47](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/47) ✔️ -- [Moments](https://help.twitch.tv/s/article/moments) claiming [#182](https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/issues/182) ✔️ -- Notifying on `@nickname` mention in the Twitch chat [#227](https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/issues/227) ✔️ +- [Moments](https://help.twitch.tv/s/article/moments) claiming [#182](https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2/issues/182) ✔️ +- Notifying on `@nickname` mention in the Twitch chat [#227](https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2/issues/227) ✔️ ## Logs feature ### Full logs @@ -185,10 +175,10 @@ If you have any issues or you want to contribute, you are welcome! But please re ``` ## How to use: -First of all please create a run.py file. You can just copy [example.py](https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/blob/master/example.py) and modify it according to your needs. + ```python # -*- coding: utf-8 -*- - +!!!!UPDATING THAT SOON!!!! import logging from colorama import Fore from TwitchChannelPointsMiner import TwitchChannelPointsMiner @@ -339,7 +329,7 @@ twitch_miner.mine(followers=True, blacklist=["user1", "user2"]) # Blacklist exa ``` ### By cloning the repository -1. Clone this repository `git clone https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2` +1. Clone this repository `git clone https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2` 2. Install all the requirements `pip install -r requirements.txt` . If you have problems with requirements, make sure to have at least Python3.6. You could also try to create a _virtualenv_ and then install all the requirements ```sh pip install virtualenv @@ -417,7 +407,7 @@ docker run --name user2 -v $(pwd)/user2.py:/usr/src/app/run.py:ro -p 5002:5000 r #### Portainer -[Link](https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/wiki/Deploy-Docker-container-in-Portainer) to the illustrated guide on how to deploy a Docker container in Portainer. +[Link](https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2/wiki/Deploy-Docker-container-in-Portainer) to the illustrated guide on how to deploy a Docker container in Portainer. ### Replit @@ -450,7 +440,7 @@ You can combine all priority but keep in mind that use `ORDER` and `POINTS_ASCEN | `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. | | `console_username`| bool | False | Adds a username to every log line in the console if True. [#602](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/602)| -| `time_zone`| str | None | Set a specific time zone for console and file loggers. Use tz database names. Example: "America/Denver" https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2/issues/205| +| `time_zone`| str | None | Set a specific time zone for console and file loggers. Use tz database names. Example: "America/Denver" https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2/issues/205| | `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) | @@ -725,7 +715,7 @@ pkg install python-pandas **4. Clone this repository** -`git clone https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2` +`git clone https://github.com/0x8fv/Twitch-Channel-Points-Miner-v2` **5. Go to the miner's directory** diff --git a/TwitchChannelPointsMiner/constants.py b/TwitchChannelPointsMiner/constants.py index c06bced..9477d89 100644 --- a/TwitchChannelPointsMiner/constants.py +++ b/TwitchChannelPointsMiner/constants.py @@ -32,7 +32,7 @@ USER_AGENTS = { BRANCH = "master" GITHUB_url = ( - "https://raw.githubusercontent.com/rdavydov/Twitch-Channel-Points-Miner-v2/" + "https://raw.githubusercontent.com/0x8fv/Twitch-Channel-Points-Miner-v2/" + BRANCH ) diff --git a/assets/charts.html b/assets/charts.html index 51bcf20..6cfb3bd 100644 --- a/assets/charts.html +++ b/assets/charts.html @@ -27,7 +27,7 @@