diff --git a/ENABLE_ANALYTICS.py b/ENABLE_ANALYTICS.py deleted file mode 100644 index 9ec9eca..0000000 --- a/ENABLE_ANALYTICS.py +++ /dev/null @@ -1,4 +0,0 @@ -# Significantly reduces memory consumption and saves some disk space. -# Remove this file if you don't need Analytics. Or rename it to something different, like "DISABLE_ANALYTICS.py". -# To enable Analytics back - just create this file again. Or rename it back to "ENABLE_ANALYTICS.py". -# This file can be empty. \ No newline at end of file diff --git a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py index f7dfd94..f000431 100644 --- a/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py +++ b/TwitchChannelPointsMiner/TwitchChannelPointsMiner.py @@ -31,17 +31,6 @@ from TwitchChannelPointsMiner.utils import ( set_default_settings, ) -DISABLE_ANALYTICS = False - -try: - import ENABLE_ANALYTICS -except ImportError: - DISABLE_ANALYTICS = True - -# Analytics switch -if DISABLE_ANALYTICS is False: - from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer - # Suppress: # - chardet.charsetprober - [feed] # - chardet.charsetprober - [get_confidence] @@ -63,6 +52,7 @@ class TwitchChannelPointsMiner: "username", "twitch", "claim_drops_startup", + "analytics", "priority", "streamers", "events_predictions", @@ -82,6 +72,7 @@ class TwitchChannelPointsMiner: username: str, password: str = None, claim_drops_startup: bool = False, + analytics: bool = False, # Settings for logging and selenium as you can see. priority: list = [Priority.STREAK, Priority.DROPS, Priority.ORDER], # This settings will be global shared trought Settings class @@ -90,7 +81,10 @@ class TwitchChannelPointsMiner: streamer_settings: StreamerSettings = StreamerSettings(), ): # Analytics switch - if DISABLE_ANALYTICS is False: + Settings.analytics = analytics + + if Settings.analytics is True: + from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer Settings.analytics_path = os.path.join(Path().absolute(), "analytics", username) Path(Settings.analytics_path).mkdir(parents=True, exist_ok=True) @@ -139,7 +133,7 @@ class TwitchChannelPointsMiner: signal.signal(sign, self.end) # Analytics switch - if DISABLE_ANALYTICS is False: + if Settings.analytics is True: def analytics( self, host: str = "127.0.0.1", diff --git a/TwitchChannelPointsMiner/classes/Settings.py b/TwitchChannelPointsMiner/classes/Settings.py index 8062408..1fdf1f8 100644 --- a/TwitchChannelPointsMiner/classes/Settings.py +++ b/TwitchChannelPointsMiner/classes/Settings.py @@ -20,7 +20,7 @@ class FollowersOrder(Enum): # Empty object shared between class class Settings(object): - __slots__ = ["logger", "streamer_settings"] + __slots__ = ["logger", "streamer_settings", "analytics"] class Events(Enum): diff --git a/TwitchChannelPointsMiner/classes/WebSocketsPool.py b/TwitchChannelPointsMiner/classes/WebSocketsPool.py index fe14048..cb565b2 100644 --- a/TwitchChannelPointsMiner/classes/WebSocketsPool.py +++ b/TwitchChannelPointsMiner/classes/WebSocketsPool.py @@ -9,7 +9,7 @@ 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.Settings import Events +from TwitchChannelPointsMiner.classes.Settings import Events, Settings from TwitchChannelPointsMiner.classes.TwitchWebSocket import TwitchWebSocket from TwitchChannelPointsMiner.constants import WEBSOCKET from TwitchChannelPointsMiner.utils import ( @@ -17,16 +17,8 @@ from TwitchChannelPointsMiner.utils import ( internet_connection_available, ) -DISABLE_ANALYTICS = False - -try: - import ENABLE_ANALYTICS -except ImportError: - DISABLE_ANALYTICS = True - logger = logging.getLogger(__name__) - class WebSocketsPool: __slots__ = ["ws", "twitch", "streamers", "events_predictions"] @@ -186,7 +178,7 @@ class WebSocketsPool: balance = message.data["balance"]["balance"] ws.streamers[streamer_index].channel_points = balance # Analytics switch - if DISABLE_ANALYTICS is False: + if Settings.analytics is True: ws.streamers[streamer_index].persistent_series( event_type=message.data["point_gain"]["reason_code"] if message.type == "points-earned" @@ -208,7 +200,7 @@ class WebSocketsPool: reason_code, earned ) # Analytics switch - if DISABLE_ANALYTICS is False: + if Settings.analytics is True: ws.streamers[streamer_index].persistent_annotations( reason_code, f"+{earned} - {reason_code}" ) diff --git a/example.py b/example.py index 4efe39c..aa16bc2 100644 --- a/example.py +++ b/example.py @@ -20,6 +20,7 @@ twitch_miner = TwitchChannelPointsMiner( Priority.DROPS, # - When we don't have anymore watch streak to catch, wait until all drops are collected over the streamers Priority.ORDER # - When we have all of the drops claimed and no watch-streak available, use the order priority (POINTS_ASCENDING, POINTS_DESCEDING) ], + analytics=False, # Disables Analytics if False. Disabling it significantly reduces memory consumption logger_settings=LoggerSettings( save=True, # If you want to save logs in a file (suggested) console_level=logging.INFO, # Level of logs - use logging.DEBUG for more info