import requests
def in_list(c, classes):
for i, sublist in enumerate(classes):
if c in sublist:
return i
return -1
def getEHB(group, duration, removeAlts):
# 254 is Legacy.
# Only change if you want to check other clans
GROUP = group
# Change the metric to what ever you want to check.
# Valid metrics can be found here: https://docs.wiseoldman.net/global-type-definitions#enum-boss
METRIC = "ehb"
# Filter alt ranks
FILTER_ALTS = removeAlts
ALT_RANK = "skiller"
ALT_OTHER = "helper"
# Grab all members
groups_response = requests.get("https://api.wiseoldman.net/v2/groups/" + GROUP)
groups_data = groups_response.json()
# List the members name and role: [(username, role), (username, role), ...]
all_members = [(membership["player"]["username"], membership['role']) for membership in groups_data["memberships"]]
# Get EHB data for all members, keeping those with EHB > 0
ranked_members = []
for i in range(len(all_members)//50):
metric_response = requests.get("https://api.wiseoldman.net/v2/groups/" + GROUP + "/gained?metric=" + METRIC + "&period=" + duration + "&limit=50&offset=" + str(i * 50))
metric_data = metric_response.json()
for player in metric_data:
if player["data"]["gained"] > 0:
ranked_members.append((player["player"]["username"], player["data"]["gained"]))
#Filter out alts and clan friends, add up total EHB
sumTotal = 0
for m, r in all_members:
if FILTER_ALTS and (r == ALT_RANK or r == ALT_OTHER):
continue
else:
valLoc = in_list(m, ranked_members)
sumTotal += ranked_members[valLoc][1]
return str(sumTotal) + " from " + str(len(ranked_members) + " out of " + str(len(all_members) + " total members."
# Print clan stats
# print("Legacy week - {}".format(getEHB("254", "week", True)))
print("Legacy month - {}".format(getEHB("254", "month", False)))
print("Infernal month - {}".format(getEHB("2545", "month", False)))
print("Clan Europe month - {}".format(getEHB("1555", "month", False)))
print("Final Boss month - {}".format(getEHB("1055", "month", False)))
print("Renatus month - {}".format(getEHB("1224", "month", False)))
print("Sentinels month - {}".format(getEHB("4567", "month", False)))
print("Zuvelox month - {}".format(getEHB("3909", "month", False)))
print("Menace month - {}".format(getEHB("7097", "month", False)))
print("Ethos month - {}".format(getEHB("6742", "month", False)))
print("Resurgent month - {}".format(getEHB("7855", "month", False)))
print("Hyperion month - {}".format(getEHB("3288", "month", False)))
print("Unknown Fear month - {}".format(getEHB("997", "month", False)))
print("Nuclear month - {}".format(getEHB("5974", "month", False)))
print("Envision month - {}".format(getEHB("7657", "month", False)))
print("Mercenary month - {}".format(getEHB("2830", "month", False)))
# print("Sanity week - {}".format(getEHB("230", "week", False)))
# print("Sanity month - {}".format(getEHB("230", "month", False)))
Click Run or press shift + ENTER to run code