Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- import json
- import time
- import urllib.request
- def parse_args():
- parser = argparse.ArgumentParser(description="Find special maps that have been lost in your Map tab")
- parser.add_argument("account",
- help="The account you want to monitor map tabs for")
- parser.add_argument("next_change_id",
- help="The change ID to start watching from. Get a recent one from https://poe.ninja/stats")
- parser.add_argument("-e", "--elder",
- action="store_true",
- default=False,
- help="Finds Elder-influenced maps")
- parser.add_argument("-s", "--shaper",
- action="store_true",
- default=False,
- help="Finds Shaper-influenced maps (other than Guardian maps)")
- parser.add_argument("-d", "--delirium",
- action="store_true",
- default=False,
- help="Finds maps with Delirium enchantments")
- parser.add_argument("-n", "--enchant",
- action="store_true",
- default=False,
- help="Finds maps with any enchantment")
- args = parser.parse_args()
- return args
- def print_stash_items(stash, print_elder, print_shaper, print_delirium, print_enchant):
- for item in stash['items']:
- matched = False
- if 'implicitMods' in item:
- if print_elder and "area is influenced by the elder" in map(str.lower, item['implicitMods']):
- matched = True
- elif print_shaper and "area is influenced by the shaper" in map(str.lower, item['implicitMods']):
- if item['extended']['baseType'] not in ["Forge of the Phoenix Map",
- "Lair of the Hydra Map",
- "Maze of the Minotaur Map",
- "Pit of the Chimera Map"]:
- matched = True
- if 'enchantMods' in item:
- if print_enchant:
- matched = True
- elif print_delirium:
- if len([mod for mod in item['enchantMods'] if "delirium" in mod.lower()]) > 0:
- matched = True
- if matched:
- print("=================================")
- if len(item['name']) > 0:
- print(item['name'])
- print(item['typeLine'])
- for prop in item['properties']:
- if prop['name'] == "Map Tier":
- # values is an array of arrays and the first element should be the tier
- # (GGG madness, or does documentation actually exist somewhere???)
- tier = prop['values'][0][0]
- print(f"Map Tier: {tier}")
- break
- if 'enchantMods' in item:
- print("--------------------")
- for enchant in item['enchantMods']:
- print(enchant)
- if 'implicitMods' in item:
- print("--------------------")
- for implicit in item['implicitMods']:
- print(implicit)
- print("=================================")
- def main():
- args = parse_args()
- account = args.account
- next_change_id = args.next_change_id
- base_url = "https://www.pathofexile.com/api/public-stash-tabs?id="
- req = urllib.request.Request(base_url + next_change_id)
- req.add_header("User-Agent", "Lost Map Finder/0.1")
- print(f"Watching map stash changes for account: {account}")
- while True:
- with urllib.request.urlopen(req) as resp:
- req_time = time.time()
- stash_data = json.load(resp)
- next_change_id = stash_data['next_change_id']
- stashes = stash_data['stashes']
- for stash in stashes:
- if stash['accountName'] != account or stash['stashType'] != "MapStash":
- continue
- print_stash_items(stash,
- print_elder=args.elder,
- print_shaper=args.shaper,
- print_delirium=args.delirium,
- print_enchant=args.enchant)
- # Rate limiting
- if len(stashes) == 0:
- # No new stashes published yet
- time.sleep(5)
- elif time.time() - req_time < 2:
- # Parsing didn't take long enough to serve as the rate limiter
- time.sleep(1)
- req.full_url = base_url + next_change_id
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment