Guest User

PoE Map Finder

a guest
Mar 28th, 2021
1,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.79 KB | None | 0 0
  1. import argparse
  2. import json
  3. import time
  4. import urllib.request
  5.  
  6. def parse_args():
  7.     parser = argparse.ArgumentParser(description="Find special maps that have been lost in your Map tab")
  8.  
  9.     parser.add_argument("account",
  10.                         help="The account you want to monitor map tabs for")
  11.     parser.add_argument("next_change_id",
  12.                         help="The change ID to start watching from. Get a recent one from https://poe.ninja/stats")
  13.     parser.add_argument("-e", "--elder",
  14.                         action="store_true",
  15.                         default=False,
  16.                         help="Finds Elder-influenced maps")
  17.     parser.add_argument("-s", "--shaper",
  18.                         action="store_true",
  19.                         default=False,
  20.                         help="Finds Shaper-influenced maps (other than Guardian maps)")
  21.     parser.add_argument("-d", "--delirium",
  22.                         action="store_true",
  23.                         default=False,
  24.                         help="Finds maps with Delirium enchantments")
  25.     parser.add_argument("-n", "--enchant",
  26.                         action="store_true",
  27.                         default=False,
  28.                         help="Finds maps with any enchantment")
  29.  
  30.     args = parser.parse_args()
  31.     return args
  32.  
  33. def print_stash_items(stash, print_elder, print_shaper, print_delirium, print_enchant):
  34.     for item in stash['items']:
  35.         matched = False
  36.  
  37.         if 'implicitMods' in item:
  38.             if print_elder and "area is influenced by the elder" in map(str.lower, item['implicitMods']):
  39.                 matched = True
  40.             elif print_shaper and "area is influenced by the shaper" in map(str.lower, item['implicitMods']):
  41.                 if item['extended']['baseType'] not in ["Forge of the Phoenix Map",
  42.                                                         "Lair of the Hydra Map",
  43.                                                         "Maze of the Minotaur Map",
  44.                                                         "Pit of the Chimera Map"]:
  45.                     matched = True
  46.  
  47.         if 'enchantMods' in item:
  48.             if print_enchant:
  49.                 matched = True
  50.             elif print_delirium:
  51.                 if len([mod for mod in item['enchantMods'] if "delirium" in mod.lower()]) > 0:
  52.                     matched = True
  53.  
  54.         if matched:
  55.             print("=================================")
  56.            
  57.             if len(item['name']) > 0:
  58.                 print(item['name'])
  59.             print(item['typeLine'])
  60.  
  61.             for prop in item['properties']:
  62.                 if prop['name'] == "Map Tier":
  63.                     # values is an array of arrays and the first element should be the tier
  64.                     # (GGG madness, or does documentation actually exist somewhere???)
  65.                     tier = prop['values'][0][0]
  66.                     print(f"Map Tier: {tier}")
  67.                     break
  68.  
  69.             if 'enchantMods' in item:
  70.                 print("--------------------")
  71.                 for enchant in item['enchantMods']:
  72.                     print(enchant)
  73.  
  74.             if 'implicitMods' in item:
  75.                 print("--------------------")
  76.                 for implicit in item['implicitMods']:
  77.                     print(implicit)
  78.  
  79.             print("=================================")
  80.  
  81. def main():
  82.     args = parse_args()
  83.  
  84.     account = args.account
  85.     next_change_id = args.next_change_id
  86.  
  87.     base_url = "https://www.pathofexile.com/api/public-stash-tabs?id="
  88.  
  89.     req = urllib.request.Request(base_url + next_change_id)
  90.     req.add_header("User-Agent", "Lost Map Finder/0.1")
  91.  
  92.     print(f"Watching map stash changes for account: {account}")
  93.    
  94.     while True:
  95.         with urllib.request.urlopen(req) as resp:
  96.             req_time = time.time()
  97.             stash_data = json.load(resp)
  98.  
  99.             next_change_id = stash_data['next_change_id']
  100.             stashes = stash_data['stashes']
  101.  
  102.             for stash in stashes:
  103.                 if stash['accountName'] != account or stash['stashType'] != "MapStash":
  104.                     continue
  105.  
  106.                 print_stash_items(stash,
  107.                                   print_elder=args.elder,
  108.                                   print_shaper=args.shaper,
  109.                                   print_delirium=args.delirium,
  110.                                   print_enchant=args.enchant)
  111.  
  112.             # Rate limiting
  113.             if len(stashes) == 0:
  114.                 # No new stashes published yet
  115.                 time.sleep(5)
  116.             elif time.time() - req_time < 2:
  117.                 # Parsing didn't take long enough to serve as the rate limiter
  118.                 time.sleep(1)
  119.  
  120.             req.full_url = base_url + next_change_id
  121.  
  122. if __name__ == '__main__':
  123.     main()
  124.  
Advertisement
Add Comment
Please, Sign In to add comment