Skip to content

Instantly share code, notes, and snippets.

@Voltikor
Created November 10, 2024 23:14
Show Gist options
  • Save Voltikor/748bf5051c70de2d561e49b008e72089 to your computer and use it in GitHub Desktop.
Save Voltikor/748bf5051c70de2d561e49b008e72089 to your computer and use it in GitHub Desktop.
Script to copy 7tv emote sets from other users
### Non-asynchronous version to avoid rate limiting ###
import requests
import time
# Emote set ID can be found on the url of said set
emote_set_id_to_copy_from = "XXXXXXXXXXXXXXXXXXXXXXXXXX"
# Emote set ID : Bearer token
# Bearer token can be obtained several ways
# Easiest is: Logged in, press F12 to open DevTools, navigate to the Application tab, find and click on https://7tv.app under Local storage
# You'll then copy and paste the value under "7tv-auth-token" here
emote_sets_to_copy_to = {
"XXXXXXXXXXXXXXXXXXXXXXXXXX": "7tv-auth-token"
}
def get_emote_set(emote_set_id):
r = requests.get(f"https://7tv.io/v3/emote-sets/{emote_set_id}")
if r.status_code != 200:
print("Error getting desired emote set")
return []
return r.json().get("emotes", [])
def copy_emotes():
emotes = get_emote_set(emote_set_id_to_copy_from)
for k, v in emote_sets_to_copy_to.items():
headers = {"Authorization": f"Bearer {v}"}
chunk = []
for e in emotes:
entry = {
"operationName": "ChangeEmoteInSet",
"variables": {"action": "ADD", "id": k, "emote_id": e["id"], "name": e["name"]},
"query": "mutation ChangeEmoteInSet($id: ObjectID!, $action: ListItemAction!, $emote_id: ObjectID!, $name: String) {\n emoteSet(id: $id) {\n id\n emotes(id: $emote_id, action: $action, name: $name) {\n id\n name\n __typename\n }\n __typename\n }\n}"
}
chunk.append(entry)
# Send the chunk if it has reached 30 entries or is the last emote
# Lower chunk limits tend to work more reliably (sometimes emotes won't be added for no reason, just run again with lower limit)
if len(chunk) == 30 or e == emotes[-1]:
response = requests.post("https://7tv.io/v3/gql", json=chunk, headers=headers)
if response.status_code != 200:
print(f"Error posting emote chunk: {response.status_code}\n{response.json()}")
else:
print(f"Posted emote chunk: {chunk}\n{response.json()}")
chunk = []
time.sleep(30) # Delay between requests in seconds
# Careful to not get rate limited, choose a high enough value
def main():
start = time.time()
copy_emotes()
print(f"Completed in {time.time() - start} seconds")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment