Merge pull request #745 from 0x8fv/rdavydov-master
hotfix change GraphQL operations to use UserByLogin for fetching user data and improve response handling in Twitch and TwitchLogin classes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
__version__ = "2.0.0"
|
||||
__version__ = "2.0.1"
|
||||
from .TwitchChannelPointsMiner import TwitchChannelPointsMiner
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -197,8 +197,8 @@ class Twitch(object):
|
||||
streamer.set_offline()
|
||||
|
||||
def get_channel_id(self, streamer_username):
|
||||
json_data = copy.deepcopy(GQLOperations.ReportMenuItem)
|
||||
json_data["variables"] = {"channelLogin": streamer_username}
|
||||
json_data = copy.deepcopy(GQLOperations.GetIDFromLogin)
|
||||
json_data["variables"]["login"] = streamer_username
|
||||
json_response = self.post_gql_request(json_data)
|
||||
if (
|
||||
"data" not in json_response
|
||||
@@ -826,12 +826,16 @@ class Twitch(object):
|
||||
|
||||
def __get_drops_dashboard(self, status=None):
|
||||
response = self.post_gql_request(GQLOperations.ViewerDropsDashboard)
|
||||
campaigns = response["data"]["currentUser"]["dropCampaigns"] or []
|
||||
campaigns = (
|
||||
response.get("data", {})
|
||||
.get("currentUser", {})
|
||||
.get("dropCampaigns", [])
|
||||
or []
|
||||
)
|
||||
|
||||
if status is not None:
|
||||
campaigns = (
|
||||
list(filter(lambda x: x["status"] ==
|
||||
status.upper(), campaigns)) or []
|
||||
list(filter(lambda x: x["status"] == status.upper(), campaigns)) or []
|
||||
)
|
||||
|
||||
return campaigns
|
||||
@@ -850,9 +854,15 @@ class Twitch(object):
|
||||
}
|
||||
|
||||
response = self.post_gql_request(json_data)
|
||||
if not isinstance(response, list):
|
||||
logger.debug("Unexpected campaigns response format, skipping chunk")
|
||||
continue
|
||||
for r in response:
|
||||
if r["data"]["user"] is not None:
|
||||
result.append(r["data"]["user"]["dropCampaign"])
|
||||
drop_campaign = (
|
||||
r.get("data", {}).get("user", {}).get("dropCampaign", None)
|
||||
)
|
||||
if drop_campaign is not None:
|
||||
result.append(drop_campaign)
|
||||
return result
|
||||
|
||||
def __sync_campaigns(self, campaigns):
|
||||
@@ -921,6 +931,7 @@ class Twitch(object):
|
||||
|
||||
def sync_campaigns(self, streamers, chunk_size=3):
|
||||
campaigns_update = 0
|
||||
campaigns = []
|
||||
while self.running:
|
||||
try:
|
||||
# Get update from dashboard each 60minutes
|
||||
@@ -977,6 +988,7 @@ class Twitch(object):
|
||||
|
||||
except (ValueError, KeyError, requests.exceptions.ConnectionError) as e:
|
||||
logger.error(f"Error while syncing inventory: {e}")
|
||||
campaigns = []
|
||||
self.__check_connection_handler(chunk_size)
|
||||
|
||||
self.__chuncked_sleep(60, chunk_size=chunk_size)
|
||||
|
||||
@@ -341,8 +341,8 @@ class TwitchLogin(object):
|
||||
return user_id
|
||||
|
||||
def __set_user_id(self):
|
||||
json_data = copy.deepcopy(GQLOperations.ReportMenuItem)
|
||||
json_data["variables"] = {"channelLogin": self.username}
|
||||
json_data = copy.deepcopy(GQLOperations.GetIDFromLogin)
|
||||
json_data["variables"]["login"] = self.username
|
||||
response = self.session.post(GQLOperations.url, json=json_data)
|
||||
|
||||
if response.status_code == 200:
|
||||
|
||||
@@ -170,12 +170,13 @@ class GQLOperations:
|
||||
}
|
||||
},
|
||||
}
|
||||
ReportMenuItem = { # Use for replace https://api.twitch.tv/helix/users?login={self.username}
|
||||
"operationName": "ReportMenuItem",
|
||||
GetIDFromLogin = {
|
||||
"operationName": "GetIDFromLogin",
|
||||
"variables": {"login": None},
|
||||
"extensions": {
|
||||
"persistedQuery": {
|
||||
"version": 1,
|
||||
"sha256Hash": "8f3628981255345ca5e5453dfd844efffb01d6413a9931498836e6268692a30c",
|
||||
"sha256Hash": "94e82a7b1e3c21e186daa73ee2afc4b8f23bade1fbbff6fe8ac133f50a2f58ca",
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user