|
23 | 23 | ) |
24 | 24 | from TwitchChannelPointsMiner.classes.Settings import Priority, Settings |
25 | 25 | from TwitchChannelPointsMiner.classes.TwitchLogin import TwitchLogin |
26 | | -from TwitchChannelPointsMiner.constants import API, CLIENT_ID, GQLOperations |
| 26 | +from TwitchChannelPointsMiner.constants import CLIENT_ID, GQLOperations |
27 | 27 | from TwitchChannelPointsMiner.utils import ( |
28 | 28 | _millify, |
29 | 29 | create_chunks, |
@@ -143,33 +143,34 @@ def check_streamer_online(self, streamer): |
143 | 143 | streamer.set_offline() |
144 | 144 |
|
145 | 145 | def get_channel_id(self, streamer_username): |
146 | | - json_response = self.__do_helix_request(f"/users?login={streamer_username}") |
147 | | - if "data" not in json_response: |
| 146 | + json_data = copy.deepcopy(GQLOperations.ReportMenuItem) |
| 147 | + json_data["variables"] = {"channelLogin": streamer_username} |
| 148 | + json_response = self.post_gql_request(json_data) |
| 149 | + if ( |
| 150 | + "data" not in json_response |
| 151 | + or "user" not in json_response["data"] |
| 152 | + or json_response["data"]["user"] is None |
| 153 | + ): |
148 | 154 | raise StreamerDoesNotExistException |
149 | 155 | else: |
150 | | - data = json_response["data"] |
151 | | - if len(data) >= 1: |
152 | | - return data[0]["id"] |
153 | | - else: |
154 | | - raise StreamerDoesNotExistException |
155 | | - |
156 | | - def get_followers(self, first=100): |
157 | | - followers = [] |
158 | | - pagination = {} |
159 | | - while 1: |
160 | | - query = f"/users/follows?from_id={self.twitch_login.get_user_id()}&first={first}" |
161 | | - if pagination != {}: |
162 | | - query += f"&after={pagination['cursor']}" |
163 | | - |
164 | | - json_response = self.__do_helix_request(query) |
165 | | - pagination = json_response["pagination"] |
166 | | - followers += [fw["to_login"].lower() for fw in json_response["data"]] |
167 | | - time.sleep(random.uniform(0.3, 0.7)) |
168 | | - |
169 | | - if pagination == {}: |
170 | | - break |
| 156 | + return json_response["data"]["user"]["id"] |
171 | 157 |
|
172 | | - return followers |
| 158 | + def get_followers(self): |
| 159 | + json_data = copy.deepcopy(GQLOperations.PersonalSections) |
| 160 | + json_response = self.post_gql_request(json_data) |
| 161 | + try: |
| 162 | + if ( |
| 163 | + "data" in json_response |
| 164 | + and "personalSections" in json_response["data"] |
| 165 | + and json_response["data"]["personalSections"] != [] |
| 166 | + ): |
| 167 | + return [ |
| 168 | + fw["user"]["login"] |
| 169 | + for fw in json_response["data"]["personalSections"][0]["items"] |
| 170 | + if fw["user"] is not None |
| 171 | + ] |
| 172 | + except KeyError: |
| 173 | + return [] |
173 | 174 |
|
174 | 175 | def update_raid(self, streamer, raid): |
175 | 176 | if streamer.raid != raid: |
@@ -211,14 +212,6 @@ def __check_connection_handler(self, chunk_size): |
211 | 212 | ) |
212 | 213 | self.__chuncked_sleep(random_sleep * 60, chunk_size=chunk_size) |
213 | 214 |
|
214 | | - def __do_helix_request(self, query, response_as_json=True): |
215 | | - url = f"{API}/helix/{query.strip('/')}" |
216 | | - response = self.twitch_login.session.get(url) |
217 | | - logger.debug( |
218 | | - f"Query: {query}, Status code: {response.status_code}, Content: {response.json()}" |
219 | | - ) |
220 | | - return response.json() if response_as_json is True else response |
221 | | - |
222 | 215 | def post_gql_request(self, json_data): |
223 | 216 | try: |
224 | 217 | response = requests.post( |
@@ -362,14 +355,12 @@ def send_minute_watched_events(self, streamers, priority, chunk_size=3): |
362 | 355 | drop.has_preconditions_met is not False |
363 | 356 | and drop.is_printable is True |
364 | 357 | ): |
365 | | - # print("=" * 125) |
366 | 358 | logger.info( |
367 | 359 | f"{streamers[index]} is streaming {streamers[index].stream}" |
368 | 360 | ) |
369 | 361 | logger.info(f"Campaign: {campaign}") |
370 | 362 | logger.info(f"Drop: {drop}") |
371 | 363 | logger.info(f"{drop.progress_bar()}") |
372 | | - # print("=" * 125) |
373 | 364 |
|
374 | 365 | except requests.exceptions.ConnectionError as e: |
375 | 366 | logger.error(f"Error while trying to send minute watched: {e}") |
@@ -541,7 +532,9 @@ def __get_campaigns_details(self, campaigns): |
541 | 532 | } |
542 | 533 |
|
543 | 534 | response = self.post_gql_request(json_data) |
544 | | - result += list(map(lambda x: x["data"]["user"]["dropCampaign"], response)) |
| 535 | + for r in response: |
| 536 | + if r["data"]["user"] is not None: |
| 537 | + result.append(r["data"]["user"]["dropCampaign"]) |
545 | 538 | return result |
546 | 539 |
|
547 | 540 | def __sync_campaigns(self, campaigns): |
|
0 commit comments