Skip to content

Instantly share code, notes, and snippets.

@aurorapar
Created June 9, 2016 00:26
Show Gist options
  • Save aurorapar/7904e4e2e1f5f9a948d5b2d3a27943c4 to your computer and use it in GitHub Desktop.
Save aurorapar/7904e4e2e1f5f9a948d5b2d3a27943c4 to your computer and use it in GitHub Desktop.
from lxml import html
import requests, os
wowhead = "http://www.wowhead.com/item="
wantedStats = ['Agility or Strength or Intellect', 'Strength', 'Agility', 'Intellect', 'Attack Power', 'Spell Power', 'Haste', 'Critical Strike', 'Mastery', 'Versatility', 'Multistrike']
def getItemNumber(itemNumber=114979):
if itemNumber == 114979:
itemNumber = raw_input("Please enter the item number you wish to test:\n\t")
try:
return int(itemNumber)
except:
print "You did not enter a valid item number"
itemNumber = getItemNumber()
def getFileName(fileName='blah'):
if fileName == 'blah':
fileName = raw_input("Please enter the Character-Spec that you want to test:\n\t")
if fileName in os.listdir(os.getcwd()):
return fileName
else:
print "You did not enter a valid file name"
fileName = getFileName('blah')
def getItemScore(formattedStats):
itemValue = 0
for x in formattedStats:
if x != formattedStats[len(formattedStats)-1]:
statValue = x.split(' ')[0]
statName = x.replace(statValue + ' ', '').replace('[', '').replace(']', '')
if statName in wantedStats[0]:
itemValue += statRatios[wantedStats[0]] * float(statValue)
else:
itemValue += statRatios[statName] * float(statValue)
return itemValue
def getStatRatios():
statWeights = {}
character = open(getFileName(), 'r+')
for line in character:
for stat in wantedStats:
if stat in line:
statWeights[stat] = float(line.split(' ')[0])
if stat in wantedStats[0]:
statWeights[wantedStats[0]] = float(line.split(' ')[0])
character.close()
return statWeights
def queryItem(itemQueryNumber):
url=wowhead+"%s/"%itemQueryNumber
page = requests.get(url)
tree = html.fromstring(page.content)
mainStat = tree.xpath('//span/text()')
name = str(tree.xpath('//title/text()')[0]).split('-')[0]
formattedStats = []
for x in mainStat:
potentialStat = x
try:
potentialStat = str(x)
if 'Strength' in potentialStat or 'Agility' in potentialStat or 'Intellect' in potentialStat:
potentialStat.replace('+','').replace('[','').replace(']','')
formattedStats.append(potentialStat)
if ') Set' in potentialStat and ' set ' not in name:
name += '!!! has a set bonus!!!'
if 'Use' in potentialStat and ' use 'not in name:
name += '!!! has an on use effect!!!'
if 'Equip:' in potentialStat and ' on proc 'not in name:
name += '!!! has an on proc effect!!!'
except:
potentialStat = x.encode('ascii', 'ignore')
formattedStats.append(potentialStat)
formattedStats.append(name)
return formattedStats
statRatios = getStatRatios()
itemQueryOne = getItemNumber()
statListOne = queryItem(itemQueryOne)
itemScoreOne = getItemScore(statListOne)
itemQueryTwo = getItemNumber()
statListTwo = queryItem(itemQueryTwo)
itemScoreTwo = getItemScore(statListTwo)
print "\n\t" + statListOne[len(statListOne)-1] + "\n\t vs. \n\t" + statListTwo[len(statListTwo)-1]
if itemScoreOne > itemScoreTwo:
print "\n%s is better"%statListOne[len(statListOne)-1]
else:
print "\n%s is better"%statListTwo[len(statListTwo)-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment