Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- shadow priest best in slot shenanigans
- by dusknoir
- powered by wowhead
- """
- import urllib.request, urllib.error
- import xml.etree.ElementTree as etree
- import json
- import re
- class ShadowPriestBestInSlot:
- """Shadow priest best-in-slot calculator."""
- # item-related configuration
- level = 80
- amount_of_items = 15
- fill_sockets = True
- # scale factors
- scale_factors = {
- # These scale factors were extracted from:
- # http://shadowpriest.com/viewtopic.php?f=62&t=22720
- # They were last updated on July 12 2009.
- "splpwr": 1,
- "critstrkrtng": 0.76,
- "hastertng": 0.65,
- "spi": 0.34,
- "int": 0.23,
- "color_socket": 23 if fill_sockets else 0,
- "meta_socket": 70 if fill_sockets else 0, # http://shadowpriest.com/viewtopic.php?f=62&t=22720
- }
- # wowhead configuration
- slots = {
- "back": 16,
- "chest": 5,
- "feet": 8,
- "finger": 11,
- "hands": 10,
- "head": 1,
- "off-hand": 23,
- "legs": 7,
- "main-hand": 21,
- "neck": 2,
- "ranged": 15,
- "shoulder": 3,
- "two-hand": 17,
- "waist": 6,
- "wrist": 9, }
- side = 2 # should be 1 or 2 to avoid duplicates
- usable_by = 5 # priests
- wowhead_locale = "www" # es/de/fr/ru/en; repr "en" as "www"
- wowhead_url = "http://{0}.wowhead.com/?{1}"
- # declarations
- bis_list = {}
- # internal config
- auto_fetch = False
- def __init__(self, scale_factors=scale_factors, locale=wowhead_locale):
- """creates an instance and localizes any supplied arguments"""
- if scale_factors != self.scale_factors: self.scale_factors = scale_factors
- if locale != self.wowhead_locale: self.wowhead_locale = locale
- if self.auto_fetch: self.get_bis()
- self.slots = {"back": 16}
- def get_bis(self):
- """fetches shadow bis info and returns it"""
- for slot, sid in self.slots.items():
- args = {
- "minrl": self.level, "maxrl": self.level,
- "ub": self.usable_by,
- "sl": sid,
- "si": self.side,
- "cr": 123, "crs": 1, "crv": 0,
- }
- for item in self._item_list(**args):
- self.bis_list[slot] = (
- item[0],
- item[1],
- #self._item_pp(self._item_stats(item['id'])
- self._item_pp(self._item_stats(49482)),
- )
- def _item_stats(self, iid):
- """fetches a wowhead item url and returns it as a xml.dom.minidom element"""
- url = self.wowhead_url.format(self.wowhead_locale, "item="+str(iid)+"&xml")
- data = urllib.request.urlopen(url).read()
- idata = etree.fromstring(data)
- idata = "{\n" + idata[0][9].text
- idata = idata.replace(",", ",\n")
- idata = idata.replace(":", "\": ")
- idata = idata.replace("\n", "\n \"")
- idata = idata + "\n}"
- data = json.loads(idata)
- return data
- def _item_pp(self, idata):
- """gets the pseudopower of an item; requires data from _item_info"""
- pp = 0
- for stat in self.scale_factors.keys():
- if stat in idata:
- pp += idata[stat] * self.scale_factors[stat]
- print(str(pp) + " (added {0} {1})".format(idata[stat], stat))
- if "nsockets" in idata:
- # determine gem values
- for i in range(0, idata['nsockets']):
- # if the gem is a meta
- if idata['socket'+str(i+1)] is 1:
- pp += self.scale_factors['meta_socket']
- print(str(pp) + " (added meta gem)")
- else:
- pp += self.scale_factors['color_socket']
- print(str(pp) + " (added color gem)")
- return pp
- def _item_list(self, **kwargs):
- """grabs a list of relevant item ids in order of their spell power (for some reason)"""
- filters = ";".join("{0}={1}".format(k,v) for k,v in kwargs.items())
- url = self.wowhead_url.format(self.wowhead_locale, "items&filter="+filters)
- data = urllib.request.urlopen(url).read()
- return (
- (1, url),
- (1, url),
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement