Skip to content

Commit

Permalink
Merge pull request #30 from Element21/master
Browse files Browse the repository at this point in the history
Use comma instead of period for delimiter
  • Loading branch information
Tkd-Alex authored Feb 1, 2021
2 parents 3357c3b + e112be2 commit 2d1997b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 30 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,19 @@ For the bet system the script use Selenium. Could be usefull understand how to M
Outcome1(NO (PINK) Points: 2M, Users: 146 (56.15%), Odds: 1.31 (76.34%))
Result: {'type': 'LOSE', 'won': 0}
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username, channel_id=0000000, channel_points=67247), Gained (end-start): -7838
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username, channel_id=0000000, channel_points=67247), Total points gained (after farming - before farming): -7838
%d/%m/%y %H:%M:%S - 💰 WATCH(35 times, 350 gained), CLAIM(11 times, 550 gained), PREDICTION(1 times, 6531 gained)
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username1, channel_id=0000000, channel_points=4240), Gained (end-start): 0
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username2, channel_id=0000000, channel_points=61365), Gained (end-start): 977
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username1, channel_id=0000000, channel_points=4240), Total points gained (after farming - before farming): 0
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username2, channel_id=0000000, channel_points=61365), Total points gained (after farming - before farming): 977
%d/%m/%y %H:%M:%S - 💰 WATCH(11 times, 132 gained), REFUND(1 times, 605 gained), CLAIM(4 times, 240 gained)
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username3, channel_id=0000000, channel_points=6815), Gained (end-start): 0
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username4, channel_id=0000000, channel_points=16386), Gained (end-start): 0
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username5, channel_id=0000000, channel_points=25960), Gained (end-start): 1680
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username3, channel_id=0000000, channel_points=6815), Total points gained (after farming - before farming): 0
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username4, channel_id=0000000, channel_points=16386), Total points gained (after farming - before farming): 0
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username5, channel_id=0000000, channel_points=25960), Total points gained (after farming - before farming): 1680
%d/%m/%y %H:%M:%S - 💰 WATCH(53 times, 530 gained), CLAIM(17 times, 850 gained)
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username6, channel_id=0000000, channel_points=9430), Gained (end-start): 1120
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username6, channel_id=0000000, channel_points=9430), Total points gained (after farming - before farming): 1120
%d/%m/%y %H:%M:%S - 💰 WATCH(42 times, 420 gained), WATCH_STREAK(1 times, 450 gained), CLAIM(14 times, 700 gained)
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username7, channel_id=0000000, channel_points=2380), Gained (end-start): 0
%d/%m/%y %H:%M:%S - 🎤 Streamer(username=streamer-username8, channel_id=0000000, channel_points=10230), Gained (end-start): 0
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username7, channel_id=0000000, channel_points=2380), Total points gained (after farming - before farming): 0
%d/%m/%y %H:%M:%S - 🤖 Streamer(username=streamer-username8, channel_id=0000000, channel_points=10230), Total points gained (after farming - before farming): 0
```

## How to use:
Expand Down
6 changes: 3 additions & 3 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
TwitchBrowser,
)
from TwitchChannelPointsMiner.classes.WebSocketsPool import WebSocketsPool
from TwitchChannelPointsMiner.utils import get_user_agent
from TwitchChannelPointsMiner.utils import _millify, get_user_agent

# Suppress warning for urllib3.connectionpool (selenium close connection)
# Suppress also the selenium logger please
Expand Down Expand Up @@ -103,7 +103,7 @@ def run(self, streamers: list = [], followers=False):
# Append at the end with lowest priority
followers_array = self.twitch.get_followers()
logger.info(
f"Load {len(followers_array)} followers from your profile!",
f"Loading {len(followers_array)} followers from your profile!",
extra={"emoji": ":clipboard:"},
)
streamers += [fw for fw in followers_array if fw not in streamers]
Expand Down Expand Up @@ -257,7 +257,7 @@ def __print_report(self):
for streamer_index in range(0, len(self.streamers)):
self.streamers[streamer_index].set_less_printing(False)
logger.info(
f"{self.streamers[streamer_index]}, Total Points Gained (after farming - before farming): {self.streamers[streamer_index].channel_points - self.original_streamers[streamer_index].channel_points}",
f"{self.streamers[streamer_index]}, Total points gained (after farming - before farming): {_millify(self.streamers[streamer_index].channel_points - self.original_streamers[streamer_index].channel_points)}",
extra={"emoji": ":robot:"},
)
if self.streamers[streamer_index].history != {}:
Expand Down
8 changes: 3 additions & 5 deletions TwitchChannelPointsMiner/classes/Bet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import logging
from enum import Enum, auto

from millify import millify

from TwitchChannelPointsMiner.utils import float_round
from TwitchChannelPointsMiner.utils import _millify, float_round

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -74,11 +72,11 @@ def update_outcomes(self, outcomes):
self.__clear_outcomes()

def __repr__(self):
return f"Bet(TotalUsers={millify(self.total_users)}, TotalPoints={millify(self.total_points)}), Decision={self.decision})\n\t\tOutcome0({self.get_outcome(0)})\n\t\tOutcome1({self.get_outcome(1)})"
return f"Bet(TotalUsers={_millify(self.total_users)}, TotalPoints={_millify(self.total_points)}), Decision={self.decision})\n\t\tOutcome0({self.get_outcome(0)})\n\t\tOutcome1({self.get_outcome(1)})"

def get_outcome(self, index):
outcome = self.outcomes[index]
return f"{outcome['title']} ({outcome['color']}), Points: {millify(outcome['total_points'])}, Users: {millify(outcome['total_users'])} ({outcome['percentage_users']}%), Odds: {outcome['odds']} ({outcome['odds_percentage']}%)"
return f"{outcome['title']} ({outcome['color']}), Points: {_millify(outcome['total_points'])}, Users: {_millify(outcome['total_users'])} ({outcome['percentage_users']}%), Odds: {outcome['odds']} ({outcome['odds_percentage']}%)"

def __clear_outcomes(self):
for index in range(0, len(self.outcomes)):
Expand Down
13 changes: 6 additions & 7 deletions TwitchChannelPointsMiner/classes/Streamer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
import time

from millify import prettify

from TwitchChannelPointsMiner.classes.Stream import Stream
from TwitchChannelPointsMiner.constants.twitch import URL
from TwitchChannelPointsMiner.utils import _millify

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -33,16 +32,16 @@ def __init__(self, username, channel_id, less_printing: bool = False):

def __repr__(self):
return (
f"{self.username} ({prettify(self.channel_points, '.')} points)"
f"{self.username} ({_millify(self.channel_points)} points)"
if self.less_printing is True
else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={prettify(self.channel_points, '.')})"
else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})"
)

def __str__(self):
return (
f"{self.username} ({prettify(self.channel_points, '.')} points)"
f"{self.username} ({_millify(self.channel_points)} points)"
if self.less_printing is True
else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={prettify(self.channel_points, '.')})"
else f"Streamer(username={self.username}, channel_id={self.channel_id}, channel_points={_millify(self.channel_points)})"
)

def set_offline(self):
Expand All @@ -63,7 +62,7 @@ def set_online(self):
def print_history(self):
return ", ".join(
[
f"{key}({self.history[key]['counter']} times, {prettify(self.history[key]['amount'], '.')} gained)"
f"{key}({self.history[key]['counter']} times, {_millify(self.history[key]['amount'])} gained)"
for key in self.history
]
)
Expand Down
5 changes: 2 additions & 3 deletions TwitchChannelPointsMiner/classes/TwitchBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from enum import Enum, auto
from pathlib import Path

from millify import prettify
from selenium import webdriver
from selenium.common.exceptions import JavascriptException, TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
Expand All @@ -17,7 +16,7 @@
from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction
from TwitchChannelPointsMiner.constants.browser import Javascript, Selectors
from TwitchChannelPointsMiner.constants.twitch import URL
from TwitchChannelPointsMiner.utils import bet_condition, get_user_agent
from TwitchChannelPointsMiner.utils import _millify, bet_condition, get_user_agent

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -339,7 +338,7 @@ def place_bet(self, event: EventPrediction):

try:
logger.info(
f"Going to write: {prettify(decision['amount'], '.')} channel points on input {decision['choice']}",
f"Going to write: {_millify(decision['amount'])} channel points on input {decision['choice']}",
extra={"emoji": ":wrench:"},
)
if (
Expand Down
4 changes: 2 additions & 2 deletions TwitchChannelPointsMiner/classes/WebSocketsPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import time

from dateutil import parser
from millify import millify

from TwitchChannelPointsMiner.classes.EventPrediction import EventPrediction
from TwitchChannelPointsMiner.classes.Exceptions import TimeBasedDropNotFound
Expand All @@ -14,6 +13,7 @@
from TwitchChannelPointsMiner.classes.TwitchWebSocket import TwitchWebSocket
from TwitchChannelPointsMiner.constants.twitch import WEBSOCKET
from TwitchChannelPointsMiner.utils import (
_millify,
bet_condition,
calculate_start_after,
get_streamer_index,
Expand Down Expand Up @@ -268,7 +268,7 @@ def on_message(ws, message):
if message.type == "prediction-result":
event_result = message.data["prediction"]["result"]
logger.info(
f"{ws.events_predictions[event_id]} - Result: {event_result['type']}, Points won: {millify(event_result['points_won']) if event_result['points_won'] else 0}",
f"{ws.events_predictions[event_id]} - Result: {event_result['type']}, Points won: {_millify(event_result['points_won']) if event_result['points_won'] else 0}",
extra={"emoji": ":bar_chart:"},
)
points_won = (
Expand Down
6 changes: 6 additions & 0 deletions TwitchChannelPointsMiner/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@
from datetime import datetime, timezone
from random import randrange

from millify import millify

from TwitchChannelPointsMiner.constants.browser import USER_AGENTS


def _millify(input, precision=2):
return millify(input, precision)


def get_streamer_index(streamers: list, channel_id) -> int:
try:
return next(
Expand Down
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
twitch_miner.mine(
["streamer1", "streamer2"], # Array of streamers (order = priority)
followers=False # Automatic download the list of your followers
)
)

0 comments on commit 2d1997b

Please sign in to comment.