Last active
April 9, 2023 13:39
-
-
Save schwittlick/00d225fb62797b4d4446d81b4fe622d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import random | |
import requests | |
def generate_holders_query(contract: str, token: int) -> str: | |
return f''' query LatestEvents {{ | |
tokens_by_pk(fa2_address: "{contract}", token_id: "{token}") {{ | |
holdings(where: {{amount: {{_gt: "0"}}}}) {{ | |
holder_address | |
amount | |
}} | |
}} | |
}} | |
''' | |
def get_data(query: str) -> dict: | |
url = 'https://api.teztok.com/v1/graphql' | |
r = requests.post(url, json={'query': query}) | |
return json.loads(r.text) | |
def parse(data: dict) -> list[str]: | |
holder_addresses = [] | |
holdings = data["data"]["tokens_by_pk"]["holdings"] | |
for holding in holdings: | |
address = holding['holder_address'] | |
amount = holding['amount'] | |
holder_addresses.extend([address for _ in range(amount)]) | |
return holder_addresses | |
def do_raffle() -> None: | |
contract = "KT1FRjrFbRbAcJYuXiwJxmQC5sYpHgXbLQ4S" | |
query = generate_holders_query(contract, 0) | |
data = get_data(query) | |
holders = parse(data) | |
random.shuffle(holders) | |
for idx, holder in enumerate(holders): | |
print(f"{holder} 🫴 token id {idx + 1}") | |
if __name__ == '__main__': | |
do_raffle() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment