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.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -143,6 +143,8 @@ cython_debug/
|
||||
# Custom files
|
||||
run.py
|
||||
chromedriver*
|
||||
/.vscode/settings.json
|
||||
config.json
|
||||
|
||||
# Folders
|
||||
cookies/*
|
||||
|
||||
6
.vscode/launch.json
vendored
6
.vscode/launch.json
vendored
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
__version__ = "1.9.9"
|
||||
__version__ = "2"
|
||||
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -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},
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
66
main.py
Normal file
66
main.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user