Created
May 27, 2022 21:07
-
-
Save ChanceToZoinks/90915ecb47ec81d3d8cdbacc963098ca to your computer and use it in GitHub Desktop.
updated ninjagetter2.py
This file contains 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
#!/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_player_skill_details(idx, data): | |
for i, skill in enumerate(data["skillDetails"]): | |
for person, l in skill["dps"].items(): | |
if int(person) == idx: | |
return (f"skill={skill['name']}", f"dps={l[0]}") | |
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] | |
skill_details = get_player_skill_details(i, builds) | |
if skill_details: # this could be None | |
c["skill"] = skill_details[0] | |
c["dps"] = skill_details[1] | |
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