This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
claim_bonus.py
34 lines (27 loc) · 1.7 KB
/
claim_bonus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from exceptions import StreamerDoesNotExistException
from twitch_data import get_channel_id, post_gql_request
# For documentation on Twitch GraphQL API see:
# https://www.apollographql.com/docs/
# https://github.com/mauricew/twitch-graphql-api
# Full list of available methods: https://azr.ivr.fi/schema/query.doc.html (a bit outdated)
def claim_channel_points_bonus(streamer_login, claim_id):
print(f"Claiming the bonus for {streamer_login}!")
json_data = {"operationName": "ClaimCommunityPoints",
"variables": {"input": {"channelID": get_channel_id(streamer_login), "claimID": claim_id}},
"extensions": {"persistedQuery": {"version": 1, "sha256Hash": "46aaeebe02c99afdf4fc97c7c0cba964124bf6b0af229395f1f6d1feed05b3d0"}}}
post_gql_request(json_data)
# Load the amount of current points for a channel, check if a bonus is available
def load_channel_points_context(streamer_login):
json_data = {"operationName": "ChannelPointsContext",
"variables": {"channelLogin": streamer_login},
"extensions": {"persistedQuery": {"version": 1, "sha256Hash": "9988086babc615a918a1e9a722ff41d98847acac822645209ac7379eecb27152"}}}
response = post_gql_request(json_data)
if response["data"]["community"] is None:
raise StreamerDoesNotExistException
community_points = response["data"]["community"]["channel"]["self"]["communityPoints"]
initial_balance = community_points["balance"]
print(f"{initial_balance} channel points for {streamer_login}!")
available_claim = community_points["availableClaim"]
if available_claim is not None:
claim_id = available_claim["id"]
claim_channel_points_bonus(streamer_login, claim_id)