#!/usr/bin/python
import sys, os, os.path
import elementtree.ElementTree as ET
baseDir = '/home/gregstoll/projects/wowarmory/'
dataDir = 'data'
outputFileName = 'index.html'
REALM = 'Maiev'
beginTableStr = ''
endTableStr = ''
def getData(lXML, xpath, action, foundOutput=lambda x: '
%s | '% x, notFoundOutput='0 | '):
data = None
for it in lXML.findall(xpath):
data = action(it)
if (data != None):
return foundOutput(data)
else:
return notFoundOutput
def getNameLink(name):
return '%s' % (REALM, name, name)
def main():
# Get the names
fileName = os.path.join(baseDir, outputFileName)
inFile = open(fileName, 'r')
inLines = inFile.readlines()
inFile.close()
inLines = [x.strip() for x in inLines]
firstLine = inLines.index(beginTableStr)
lastLine = inLines.index(endTableStr)
del inLines[firstLine+1: lastLine]
dataList = []
for name in os.listdir(os.path.join(baseDir, dataDir)):
print "name %s" % name
charPath = os.path.join(baseDir, dataDir, name)
allFiles = os.listdir(charPath)
# Just get the latest one
allFiles.sort()
latestFileName = os.path.join(charPath, allFiles[-1])
latestFile = open(latestFileName, 'r')
latestData = latestFile.read()
#print latestData
latestXML = ET.XML(latestData)
for x in latestXML.findall('characterInfo/character'):
lineToAdd = ""
lineToAdd += "%s | %d | %s | %s | " % (getNameLink(x.get('name')), int(x.get('level')), x.get('race'), x.get('class'))
# health and mana and armor
lineToAdd += getData(latestXML, 'characterInfo/characterTab/characterBars/health', lambda h : h.get('effective'))
def manafn(m):
if (m.get('type') == 'm'):
return m.get('effective')
else:
return None
lineToAdd += getData(latestXML, 'characterInfo/characterTab/characterBars/secondBar', manafn)
lineToAdd += getData(latestXML, 'characterInfo/characterTab/baseStats/armor', lambda a : a.get('base'))
# + damage/healing
plusDamage = None
for type in ['arcane', 'fire', 'frost', 'holy', 'nature', 'shadow']:
for d in latestXML.findall('characterInfo/characterTab/spell/bonusDamage/%s' % type):
curDmg = int(d.get('value'))
if (plusDamage is None):
plusDamage = [curDmg, curDmg]
else:
if (curDmg < plusDamage[0]):
plusDamage[0] = curDmg
elif (curDmg > plusDamage[1]):
plusDamage[1] = curDmg
plusHealing = 0
for h in latestXML.findall('characterInfo/characterTab/spell/bonusHealing'):
plusHealing = int(h.get('value'))
if (plusDamage is None):
plusDamageText = "0"
elif (plusDamage[0] == plusDamage[1]):
plusDamageText = "%d" % (plusDamage[0])
else:
plusDamageText = "%d-%d" % (plusDamage[0], plusDamage[1])
lineToAdd += "%s | %s | " % (plusDamageText, plusHealing)
# Melee crit chance
lineToAdd += getData(latestXML, 'characterInfo/characterTab/melee/critChance', lambda m: m.get('percent'), lambda d: '%.2f | ' % float(d))
# spell crit chance
spellCrit = None
for type in ['arcane', 'fire', 'frost', 'holy', 'nature', 'shadow']:
for d in latestXML.findall('characterInfo/characterTab/spell/critChance/%s' % type):
curCrit = float(d.get('percent'))
if (spellCrit is None):
spellCrit = [curCrit, curCrit]
else:
if (curCrit < spellCrit[0]):
spellCrit[0] = curCrit
elif (curDmg > spellCrit[1]):
spellCrit[1] = curCrit
if (spellCrit is None):
spellCritText = "0.00"
elif (plusDamage[0] == plusDamage[1]):
spellCritText = "%.2f" % (spellCrit[0])
else:
spellCritText = "%.2f-%.2f" % (spellCrit[0], spellCrit[1])
lineToAdd += '%s | ' % spellCritText
# Resilience
lineToAdd += getData(latestXML, 'characterInfo/characterTab/defenses/resilience', lambda a : a.get('value'))
# Aldor v. Scyer
aldorRep = 0
scryerRep = 0
for r in latestXML.findall('characterInfo/reputationTab/factionCategory/faction'):
if (r.get('key') == 'thealdor'):
aldorRep = int(r.get('reputation'))
elif (r.get('key') == 'thescryers'):
scryerRep = int(r.get('reputation'))
repStr = '??'
if (aldorRep > scryerRep + 5000):
repStr = 'Aldor'
elif (scryerRep > aldorRep + 5000):
repStr = 'Scryer'
elif (aldorRep > scryerRep + 2500):
repStr = 'Aldor?'
elif (scryerRep > aldorRep + 2500):
repStr = "Scryer?"
lineToAdd += '%s | ' % repStr
# Get professions
numProfessions = 0
for p in latestXML.findall('characterInfo/characterTab/professions/skill'):
lineToAdd += "%s: %d/%d | " % (p.get('name'), int(p.get('value')), int(p.get('max')))
numProfessions = numProfessions + 1
while (numProfessions < 2):
lineToAdd += "(none) | "
numProfessions = numProfessions + 1
lineToAdd += "%s | " % getNameLink(x.get('name'))
lineToAdd += "
"
dataList.append(lineToAdd)
latestFile.close()
inLines[firstLine+1:firstLine+1] = dataList
outFile = open(fileName, 'w')
for line in inLines:
outFile.write(line + '\n')
outFile.close()
if (__name__ == '__main__'):
main()