as request from @Olamio implement the autoload from followers list. Close #4
This commit is contained in:
@@ -10,6 +10,7 @@ import copy
|
||||
import random
|
||||
|
||||
from datetime import datetime
|
||||
from collections import OrderedDict
|
||||
|
||||
from TwitchChannelPointsMiner.classes.Logger import LoggerSettings, configure_loggers
|
||||
from TwitchChannelPointsMiner.classes.WebSocketsPool import WebSocketsPool
|
||||
@@ -65,10 +66,10 @@ class TwitchChannelPointsMiner:
|
||||
signal.signal(signal.SIGSEGV, self.end)
|
||||
signal.signal(signal.SIGTERM, self.end)
|
||||
|
||||
def mine(self, streamers: list = []):
|
||||
self.run(streamers)
|
||||
def mine(self, streamers: list = [], followers=False):
|
||||
self.run(streamers, followers)
|
||||
|
||||
def run(self, streamers: list = []):
|
||||
def run(self, streamers: list = [], followers=False):
|
||||
if self.running:
|
||||
logger.error("You can't start multiple session of this istance!")
|
||||
else:
|
||||
@@ -80,6 +81,20 @@ class TwitchChannelPointsMiner:
|
||||
|
||||
self.twitch.login()
|
||||
|
||||
# Clear streamers array
|
||||
# Remove duplicate 3. Preserving Order: Use OrderedDict (askpython .com)
|
||||
streamers = [streamer_name.lower().strip() for streamer_name in streamers]
|
||||
streamers = list(OrderedDict.fromkeys(streamers))
|
||||
|
||||
if followers is True:
|
||||
# Append at the end with lowest priority
|
||||
followers_array = self.twitch.get_followers()
|
||||
logger.info(
|
||||
f"Load {len(followers_array)} followers from your profile",
|
||||
extra={"emoji": ":clipboard:"},
|
||||
)
|
||||
streamers += [fw for fw in followers_array if fw not in streamers]
|
||||
|
||||
for streamer_username in streamers:
|
||||
time.sleep(random.uniform(0.3, 0.7))
|
||||
streamer_username.lower().strip()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
__version__ = "2.1.1"
|
||||
__version__ = "2.2.1"
|
||||
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
|
||||
@@ -10,6 +10,7 @@ import re
|
||||
import os
|
||||
import time
|
||||
import logging
|
||||
import random
|
||||
|
||||
from base64 import b64encode
|
||||
from pathlib import Path
|
||||
@@ -211,18 +212,44 @@ class Twitch:
|
||||
time.sleep(60)
|
||||
|
||||
def get_channel_id(self, streamer_username):
|
||||
json_response = self.__do_helix_request(f"/users?login={streamer_username}")
|
||||
data = json_response["data"]
|
||||
if len(data) >= 1:
|
||||
return data[0]["id"]
|
||||
else:
|
||||
raise StreamerDoesNotExistException
|
||||
|
||||
def get_followers(self, first=100):
|
||||
followers = []
|
||||
pagination = {}
|
||||
while 1:
|
||||
query = f"/users/follows?from_id={self.twitch_login.get_user_id()}&first={first}"
|
||||
if pagination != {}:
|
||||
query += f"&after={pagination['cursor']}"
|
||||
|
||||
json_response = self.__do_helix_request(query)
|
||||
pagination = json_response["pagination"]
|
||||
followers += [fw["to_name"].lower() for fw in json_response["data"]]
|
||||
time.sleep(random.uniform(0.3, 0.7))
|
||||
|
||||
if pagination == {}:
|
||||
break
|
||||
|
||||
return followers
|
||||
|
||||
def __do_helix_request(self, query, response_as_json=True):
|
||||
url = f"https://api.twitch.tv/helix/{query.strip('/')}"
|
||||
response = requests.get(
|
||||
f"https://api.twitch.tv/helix/users?login={streamer_username}",
|
||||
url,
|
||||
headers={
|
||||
"Authorization": f"Bearer {self.twitch_login.get_auth_token()}",
|
||||
"Client-Id": TWITCH_CLIENT_ID,
|
||||
},
|
||||
)
|
||||
data = response.json()["data"]
|
||||
if len(data) >= 1:
|
||||
return data[0]["id"]
|
||||
else:
|
||||
raise StreamerDoesNotExistException
|
||||
logger.debug(
|
||||
f"Query: {query}, Status code: {response.status_code}, Content: {response.json()}"
|
||||
)
|
||||
return response.json() if response_as_json is True else response
|
||||
|
||||
def update_raid(self, streamer, raid):
|
||||
if streamer.raid != raid:
|
||||
|
||||
2
setup.py
2
setup.py
@@ -8,7 +8,7 @@ def read(fname):
|
||||
|
||||
setuptools.setup(
|
||||
name="Twitch-Channel-Points-Miner-v2",
|
||||
version="2.1.1",
|
||||
version="2.2.1",
|
||||
author="Tkd-Alex (Alessandro Maggio)",
|
||||
author_email="alex.tkd.alex@gmail.com",
|
||||
description="A simple script that will watch a stream for you and earn the channel points.",
|
||||
|
||||
Reference in New Issue
Block a user