Skip to content

Commit

Permalink
fix #85
Browse files Browse the repository at this point in the history
  • Loading branch information
rdavydov committed Dec 17, 2022
1 parent e7a1070 commit 6369fbe
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 77 deletions.
46 changes: 29 additions & 17 deletions TwitchChannelPointsMiner/TwitchChannelPointsMiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
logging.getLogger("requests").setLevel(logging.ERROR)
logging.getLogger("werkzeug").setLevel(logging.ERROR)
logging.getLogger("irc.client").setLevel(logging.ERROR)
#logging.getLogger("seleniumwire").setLevel(logging.ERROR)
logging.getLogger("seleniumwire").setLevel(logging.ERROR)
logging.getLogger("websocket").setLevel(logging.ERROR)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -84,15 +84,17 @@ def __init__(
):
# 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 your runner file (usually run.py) and try again.")
logger.error("No username, exiting...")
sys.exit(0)

# Analytics switch
Settings.enable_analytics = enable_analytics

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

self.username = username
Expand All @@ -105,7 +107,8 @@ def __init__(
streamer_settings.bet.default()
Settings.streamer_settings = streamer_settings

user_agent = get_user_agent("FIREFOX")
# user_agent = get_user_agent("FIREFOX")
user_agent = get_user_agent("CHROME")
self.twitch = Twitch(self.username, user_agent, password)

self.claim_drops_startup = claim_drops_startup
Expand All @@ -129,15 +132,18 @@ def __init__(
# Check for the latest version of the script
current_version, github_version = check_versions()

logger.info(f"Twitch Channel Points Miner v2-{current_version} (fork by rdavydov)")
logger.info("https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2")
logger.info(
f"Twitch Channel Points Miner v2-{current_version} (fork by rdavydov)")
logger.info(
"https://github.com/rdavydov/Twitch-Channel-Points-Miner-v2")

if github_version == "0.0.0":
logger.error(
"Unable to detect if you have the latest version of this script"
)
elif current_version != github_version:
logger.info(f"You are running the version {current_version} of this script")
logger.info(
f"You are running the version {current_version} of this script")
logger.info(f"The latest version on GitHub is: {github_version}")

for sign in [signal.SIGINT, signal.SIGSEGV, signal.SIGTERM]:
Expand All @@ -153,15 +159,16 @@ def analytics(
# 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")
logger.error(
"Can't start analytics(), please set enable_analytics=True")

def mine(
self,
Expand Down Expand Up @@ -207,7 +214,8 @@ def run(
streamers_dict[username] = streamer

if followers is True:
followers_array = self.twitch.get_followers(order=followers_order)
followers_array = self.twitch.get_followers(
order=followers_order)
logger.info(
f"Load {len(followers_array)} followers from your profile!",
extra={"emoji": ":clipboard:"},
Expand All @@ -230,7 +238,8 @@ def run(
if isinstance(streamers_dict[username], Streamer) is True
else Streamer(username)
)
streamer.channel_id = self.twitch.get_channel_id(username)
streamer.channel_id = self.twitch.get_channel_id(
username)
streamer.settings = set_default_settings(
streamer.settings, Settings.streamer_settings
)
Expand Down Expand Up @@ -272,7 +281,8 @@ def run(
# If we have at least one streamer with settings = claim_drops True
# Spawn a thread for sync inventory and dashboard
if (
at_least_one_value_in_settings_is(self.streamers, "claim_drops", True)
at_least_one_value_in_settings_is(
self.streamers, "claim_drops", True)
is True
):
self.sync_campaigns_thread = threading.Thread(
Expand All @@ -298,8 +308,8 @@ def run(

# Subscribe to community-points-user. Get update for points spent or gains
user_id = self.twitch.twitch_login.get_user_id()
#print(f"!!!!!!!!!!!!!! USER_ID: {user_id}")
# print(f"!!!!!!!!!!!!!! USER_ID: {user_id}")

# Fixes 'ERR_BADAUTH'
if not user_id:
logger.error("No user_id, exiting...")
Expand Down Expand Up @@ -331,7 +341,8 @@ def run(

if streamer.settings.make_predictions is True:
self.ws_pool.submit(
PubsubTopic("predictions-channel-v1", streamer=streamer)
PubsubTopic("predictions-channel-v1",
streamer=streamer)
)

refresh_context = time.time()
Expand All @@ -348,7 +359,8 @@ def run(
logger.info(
f"#{index} - The last PING was sent more than 10 minutes ago. Reconnecting to the WebSocket..."
)
WebSocketsPool.handle_reconnection(self.ws_pool.ws[index])
WebSocketsPool.handle_reconnection(
self.ws_pool.ws[index])

if ((time.time() - refresh_context) // 60) >= 30:
refresh_context = time.time()
Expand Down Expand Up @@ -445,4 +457,4 @@ def __print_report(self):
logger.info(
f"{self.streamers[streamer_index].print_history()}",
extra={"emoji": ":moneybag:"},
)
)
2 changes: 1 addition & 1 deletion TwitchChannelPointsMiner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "1.5.4"
__version__ = "1.6.0"
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner

__all__ = [
Expand Down
Loading

0 comments on commit 6369fbe

Please sign in to comment.