|
| 1 | +import json |
| 2 | +import re |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +import requests |
| 6 | + |
| 7 | +HOST_NAME = "https://www.pathofexile.com/" |
| 8 | +CHARACTER_PATH = "character-window/get-characters" |
| 9 | +PROFILE_PATH = "account/view-profile/" |
| 10 | +PASSIVE_TREE_PATH = "character-window/get-passive-skills" |
| 11 | + |
| 12 | +headers = {"User-Agent": "Path of Building Community", "Accept": ""} |
| 13 | +realm_code = "pc" |
| 14 | + |
| 15 | + |
| 16 | +def import_characters(account_name: str) -> Optional[tuple[str, dict]]: |
| 17 | + url = f"{HOST_NAME}{CHARACTER_PATH}" |
| 18 | + params = {"accountName": account_name, "realm": realm_code} |
| 19 | + try: |
| 20 | + response = requests.get(url, params=params, headers=headers, timeout=6.0) |
| 21 | + except requests.RequestException as e: |
| 22 | + print(f"Error retrieving account: {e}.") |
| 23 | + return |
| 24 | + print(response.url) |
| 25 | + characters = response.json() |
| 26 | + print(f"Character list:\n{json.dumps(characters, indent=4)}") |
| 27 | + url = f"{HOST_NAME}{PROFILE_PATH}{account_name}" |
| 28 | + try: |
| 29 | + response = requests.get(url, headers=headers, timeout=6.0) |
| 30 | + except requests.RequestException as e: |
| 31 | + print(f"Error retrieving character list: {e}.") |
| 32 | + return |
| 33 | + if m := re.search(r"/view-profile/(\w+)/characters", response.text): |
| 34 | + return m.group(1), characters |
| 35 | + |
| 36 | + |
| 37 | +def import_passive_tree(account_name: str, char_name: str): |
| 38 | + url = f"{HOST_NAME}{PASSIVE_TREE_PATH}" |
| 39 | + params = {"accountName": account_name, "character": char_name, "realm": realm_code} |
| 40 | + try: |
| 41 | + response = requests.get(url, params=params, headers=headers, timeout=6.0) |
| 42 | + except requests.RequestException as e: |
| 43 | + print(f"Error retrieving passive skill tree: {e}.") |
| 44 | + return |
| 45 | + passive_tree = response.json() |
| 46 | + print(f"Tree:\n{json.dumps(passive_tree, indent=4)}") |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == "__main__": |
| 50 | + player_name = "GlobalIdentity" |
| 51 | + player_name, player_characters = import_characters(player_name) |
| 52 | + leagues = [c["name"] for c in player_characters if c["league"] == "Ritual"] |
| 53 | + print(leagues) |
| 54 | + import_passive_tree(player_name, leagues[1]) |
0 commit comments