Check the Tips of a Repl/User (CODE)

import os

from replit_bot import post as gql
from time import sleep
# https://stackoverflow.com/questions/7016056/python-logging-not-outputting-anything
import logging
logging.root.setLevel(logging.CRITICAL)

def get_tips_of_repl(url):
    output = {}
    repl_id = gql("", "repl", {"url": url})["repl"]["id"]
    top_tippers = gql("", "tipQuery", {"id": repl_id})["repl"]["topTippers"]
    total_tips = 0
    for i in top_tippers:
        total_tips += i["totalCyclesTipped"]
        if i["user"]["username"] not in output:
            output[i["user"]["username"]] = i["totalCyclesTipped"]
        else:
            output[i["user"]["username"]] += i["totalCyclesTipped"]
    output["total_tips"] = total_tips
    return output


def get_all_total_tips(person_to_query):
    total_tips = 0
    output = {}
    x = gql("", "userPosts", {"username": person_to_query, "count": 1000000})[
        "userByUsername"
    ]["posts"]["items"]
    checked = set()
    for i in x:
        try:
            repl_id = i["repl"]["id"]
            if (repl_id not in checked):
                checked.add(repl_id)
                top_tippers = gql("", "tipQuery", {"id": repl_id})["repl"]["topTippers"]
                for i in top_tippers:
                    total_tips += i["totalCyclesTipped"]
                    if i["user"]["username"] not in output:
                        output[i["user"]["username"]] = i["totalCyclesTipped"]
                    else:
                        output[i["user"]["username"]] += i["totalCyclesTipped"]
        except Exception as e:
            print(e)
    output["total_tips"] = total_tips
    return output

print("Retrieving tips...")
print(get_all_total_tips(os.environ["REPL_OWNER"]))
4 Likes

Awesome! Did someone give you the api for this?

2 Likes

No I made this myself

1 Like