Skip to content

Instantly share code, notes, and snippets.

@ChanceToZoinks
Last active April 30, 2022 04:23
Show Gist options
  • Save ChanceToZoinks/44be937d6bf2e468f63f986bc7630326 to your computer and use it in GitHub Desktop.
Save ChanceToZoinks/44be937d6bf2e468f63f986bc7630326 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
ENDPOINT = f"https://poe.ninja/api/data/0/getbuildoverview"
PARAMS = {"overview": "archnemesis", "type": "exp", "language": "en"}
def _try_get_builds():
r = requests.get(url=ENDPOINT, params=PARAMS)
try:
return r.json()
except:
return {}
def _is_user_in_deltas(
user_idx: int, deltas: list, start_idx: int = 0, running_total: int = 0
):
for i, delta in enumerate(deltas[start_idx:]):
running_total += delta
if user_idx == running_total:
return i, running_total
def get_n_characters(n: int):
"""
Get the first n characters in the list storing their name, level, life, es, and worn unique items
"""
builds = _try_get_builds()
if builds:
characters = []
for i in range(n):
c = {}
c["name"] = builds["names"][i]
c["level"] = builds["levels"][i]
c["life"] = builds["life"][i]
c["es"] = builds["energyShield"][i]
c["uniques"] = []
for idx, unique in enumerate(builds["uniqueItems"]):
if _is_user_in_deltas(i, builds["uniqueItemUse"][str(idx)]):
c["uniques"].append(unique["name"])
characters.append(c)
return characters
else:
return "No builds found."
if __name__ == "__main__":
print(get_n_characters(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment