Skip to content

Commit

Permalink
Merge pull request #11 from rdavydov/switchable
Browse files Browse the repository at this point in the history
Switchable Analytics fix (final, I hope)
  • Loading branch information
rdavydov authored Oct 24, 2022
2 parents a411ed3 + 2a28626 commit 0a523b3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,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
enable_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
Expand Down Expand Up @@ -578,7 +578,7 @@ If you want you can toggle the dark theme with the dedicated checkbox.
| ----------- | ---------- |
| ![Light theme](https://raw.githubusercontent.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/master/assets/chart-analytics-light.png) | ![Dark theme](https://raw.githubusercontent.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/master/assets/chart-analytics-dark.png) |

For use this feature just call the `analytics` method before start mining. Read more at: [#96](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/96)
For use this feature just call the `analytics()` method before start mining. Read more at: [#96](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/96)
The chart will be autofreshed each `refresh` minutes. If you want to connect from one to second machine that have that webpanel you have to use `0.0.0.0` instead of `127.0.0.1`. With the `days_ago` arg you can select how many days you want to show by default in your analytics graph.
```python
from TwitchChannelPointsMiner import TwitchChannelPointsMiner
Expand All @@ -587,7 +587,7 @@ twitch_miner.analytics(host="127.0.0.1", port=5000, refresh=5, days_ago=7) # A
twitch_miner.mine(followers=True, blacklist=["user1", "user2"])
```

### `analytics` option in `twitch_minerfile` toggles Analytics
### `enable_analytics` option in `twitch_minerfile` toggles Analytics needed for the `analytics()` method

Disabling Analytics significantly reduces memory consumption and saves some disk space by not creating and writing `/analytics/*.json`.

Expand Down Expand Up @@ -644,4 +644,4 @@ Now when we did everything we can run miner: `python run.py`
Read more at [#92](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/92) [#76](https://github.com/Tkd-Alex/Twitch-Channel-Points-Miner-v2/issues/76)

## Disclaimer
This project comes with no guarantee or warranty. You are responsible for whatever happens from using this project. It is possible to get soft or hard banned by using this project if you are not careful. This is a personal project and is in no way affiliated with Twitch.
This project comes with no guarantee or warranty. You are responsible for whatever happens from using this project. It is possible to get soft or hard banned by using this project if you are not careful. This is a personal project and is in no way affiliated with Twitch.
33 changes: 18 additions & 15 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TwitchChannelPointsMiner:
"username",
"twitch",
"claim_drops_startup",
"analytics",
"enable_analytics",
"priority",
"streamers",
"events_predictions",
Expand All @@ -72,7 +72,7 @@ def __init__(
username: str,
password: str = None,
claim_drops_startup: bool = False,
analytics: bool = False,
enable_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
Expand All @@ -81,10 +81,9 @@ def __init__(
streamer_settings: StreamerSettings = StreamerSettings(),
):
# Analytics switch
Settings.analytics = analytics
Settings.enable_analytics = enable_analytics

if Settings.analytics is True:
from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer
if enable_analytics is True:
Settings.analytics_path = os.path.join(Path().absolute(), "analytics", username)
Path(Settings.analytics_path).mkdir(parents=True, exist_ok=True)

Expand Down Expand Up @@ -132,21 +131,25 @@ def __init__(
for sign in [signal.SIGINT, signal.SIGSEGV, signal.SIGTERM]:
signal.signal(sign, self.end)

# Analytics switch
if Settings.analytics is True:
def analytics(
self,
host: str = "127.0.0.1",
port: int = 5000,
refresh: int = 5,
days_ago: int = 7,
):
def analytics(
self,
host: str = "127.0.0.1",
port: int = 5000,
refresh: int = 5,
days_ago: int = 7,
):
# Analytics switch
if Settings.enable_analytics is True:
from TwitchChannelPointsMiner.classes.AnalyticsServer import AnalyticsServer

http_server = AnalyticsServer(
host=host, port=port, refresh=refresh, days_ago=days_ago
)
http_server.daemon = True
http_server.name = "Analytics Thread"
http_server.start()
else:
logger.error("Can't start analytics(), please set enable_analytics=True")

def mine(
self,
Expand Down Expand Up @@ -423,4 +426,4 @@ def __print_report(self):
logger.info(
f"{self.streamers[streamer_index].print_history()}",
extra={"emoji": ":moneybag:"},
)
)
4 changes: 2 additions & 2 deletions TwitchChannelPointsMiner/classes/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __str__(self):

# Empty object shared between class
class Settings(object):
__slots__ = ["logger", "streamer_settings", "analytics"]
__slots__ = ["logger", "streamer_settings", "enable_analytics"]


class Events(Enum):
Expand All @@ -47,4 +47,4 @@ def __str__(self):

@classmethod
def get(cls, key):
return getattr(cls, str(key)) if str(key) in dir(cls) else None
return getattr(cls, str(key)) if str(key) in dir(cls) else None
8 changes: 4 additions & 4 deletions TwitchChannelPointsMiner/classes/WebSocketsPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def on_message(ws, message):

ws.last_message_timestamp = message.timestamp
ws.last_message_type_channel = message.identifier

streamer_index = get_streamer_index(ws.streamers, message.channel_id)
if streamer_index != -1:
try:
Expand All @@ -178,7 +178,7 @@ def on_message(ws, message):
balance = message.data["balance"]["balance"]
ws.streamers[streamer_index].channel_points = balance
# Analytics switch
if Settings.analytics is True:
if Settings.enable_analytics is True:
ws.streamers[streamer_index].persistent_series(
event_type=message.data["point_gain"]["reason_code"]
if message.type == "points-earned"
Expand All @@ -200,7 +200,7 @@ def on_message(ws, message):
reason_code, earned
)
# Analytics switch
if Settings.analytics is True:
if Settings.enable_analytics is True:
ws.streamers[streamer_index].persistent_annotations(
reason_code, f"+{earned} - {reason_code}"
)
Expand Down Expand Up @@ -385,4 +385,4 @@ def on_message(ws, message):
WebSocketsPool.handle_reconnection(ws)

elif response["type"] == "PONG":
ws.last_pong = time.time()
ws.last_pong = time.time()
6 changes: 4 additions & 2 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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
enable_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
Expand Down Expand Up @@ -77,6 +77,8 @@
# For example, if in the mine function you don't provide any value for 'make_prediction' but you have set it on TwitchChannelPointsMiner instance, the script will take the value from here.
# If you haven't set any value even in the instance the default one will be used

#twitch_miner.analytics(host="127.0.0.1", port=5000, refresh=5, days_ago=7) # Start the Analytics web-server

twitch_miner.mine(
[
Streamer("streamer-username01", settings=StreamerSettings(make_predictions=True , follow_raid=False , claim_drops=True , watch_streak=True , bet=BetSettings(strategy=Strategy.SMART , percentage=5 , stealth_mode=True, percentage_gap=20 , max_points=234 , filter_condition=FilterCondition(by=OutcomeKeys.TOTAL_USERS, where=Condition.LTE, value=800 ) ) )),
Expand All @@ -93,4 +95,4 @@
], # Array of streamers (order = priority)
followers=False, # Automatic download the list of your followers
followers_order=FollowersOrder.ASC # Sort the followers list by follow date. ASC or DESC
)
)

0 comments on commit 0a523b3

Please sign in to comment.