# Interrogate wow armory import urllib2 import xml.dom.minidom import sys import time import os #Imports realm information from config.wtf #Deprecated. Now use infromation in the WTF/Account directory def getRealm(): f = open("../../../wtf/Config.wtf") for line in f: if "realmName" in line: realm = line.split()[2] realm = realm.replace('"','') return realm return "fail" def getCharacterSheet(character,realm): print "Character: %s \n Realm: %s" % (character, realm) strUrl = "http://armory.worldofwarcraft.com/character-sheet.xml?r=%s&n=%s" % (realm.replace( ' ', '+'), character) #print "strUrl: %s " % strUrl # # Open url. # Need to specify firefox as user agent as this makes the server return an XML file. # If this is not done we get html. # oOpener = urllib2.build_opener() oOpener.addheaders = [ ('user-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'), ] #print "Requesting..." req = urllib2.Request(strUrl) strFile = oOpener.open(req).read() #print "Got it..." #print strFile if strFile != "": oDoc = xml.dom.minidom.parseString(strFile); return oDoc else: return "fail" def getGuildName(oDoc): element = 'character'; attribute = 'guildName'; obj = getAttributes(oDoc,element,attribute); return obj["guildName"] def getProfessions(oDoc): if oDoc != "fail": element = 'skill'; attribute = ''; return getAttributes(oDoc,element,attribute); else: obj = {"professions":"No Information"} return obj def getSpec(oDoc): if oDoc!="fail": #sets up element and attribute to retrieve individual trees #TODO: Find a more programmatically correct way to do this element = "talentSpec"; att = "treeOne"; numerical = getAttributes(oDoc,element,att)[att]; if numerical != "" and numerical != "No Spec Information": out = numerical else: out = "0"; element = "talentSpec"; att = "treeTwo"; numerical = getAttributes(oDoc,element,att)[att]; if numerical != "" and numerical != "No Spec Information": out += "/%s/" % numerical else: out += "/0/"; element = "talentSpec"; att = "treeThree"; numerical = getAttributes(oDoc,element,att)[att]; if numerical != "" and numerical != "No Spec Information": out += numerical else: out += "0"; #print out obj = {"spec": "%s" % out} #print obj return obj else: print "Spec for %s failed" % character obj = {"spec":"No Information"} def getGuildList(guild, realm): print guild print realm members = []; strUrl = "http://armory.worldofwarcraft.com/guild-info.xml?r=%s&n=%s" % (realm.replace( ' ', '+'), guild.replace( ' ', '+')) print "guildURL: " + strUrl # # Open url. # Need to specify firefox as user agent as this makes the server return an XML file. # If this is not done we get html. # oOpener = urllib2.build_opener() oOpener.addheaders = [ ('user-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'), ] req = urllib2.Request( strUrl) strFile = oOpener.open(req).read() #print strFile oDoc = xml.dom.minidom.parseString(strFile) Elements = oDoc.getElementsByTagName("character") for i in range(0,len(Elements)): members.append(Elements[i].getAttribute("name")) return members; #gets the attribute of the element passed in def getAttributes(oDoc, element, attribute): if oDoc == "": print "oDoc is null"; strValue = ""; if element == "skill": attribute = "professions"; try: Elements = oDoc.getElementsByTagName("skill"); except: print "could not get information for this character" if (len(Elements) > 0): for i in range(0,len(Elements)): if (i > 0): strValue += "|" strValue += "%s:%s" % (Elements[i].getAttribute("name"), Elements[i].getAttribute("value")) #print strValue else: strValue = "No Information" else: #print "Looking for %s : %s" % (element,attribute) Elements = oDoc.getElementsByTagName(element) if len(Elements) > 0: oElement = oDoc.getElementsByTagName(element)[0] strValue = oElement.getAttribute(attribute) else: strValue = "No Spec Information" obj = {attribute : strValue} return obj #parses are saved variables file into useable information def parseLua(filePtr): localList = [] lineCount = 0; for line in filePtr: if ("guildTools_toons = {" not in line) and ("}" not in line) and lineCount !=0: line = line.replace('\n','') line = line.replace('\r','') line = line.replace('\t',''); line = line.split('"')[1] line = line.split(',')[0] localList.append(line) lineCount += 1 #print localList return localList #TODO: Compound the following method into a streamlined function serverList = [] innerList = [] charList = [] fullList = {} currentDir = os.getcwd() #change working directory to the following to access server/character information os.chdir('../../../wtf/Account') #list accounts accountList = os.listdir(os.getcwd()) currentDir = os.getcwd() #print currentDir #print accountList #loop through accounts found for account in accountList: os.chdir("%s/%s" %(os.getcwd(),account)) #returns a list of possible servers folderList = os.listdir(os.getcwd()) #weeds out non-servers from list for folder in folderList: if (os.path.isdir(folder) and folder != "SavedVariables"): serverList.append("%s/%s"%(os.getcwd(),folder)) #attempts to retrieve characters from each server for server in serverList: os.chdir(server) fileList = os.listdir(os.getcwd()) for file in fileList: if (os.path.isdir(file)): charList.append(file) serverName = server.split('/')[-1] fullList[serverName] = charList #print serverName,fullList[serverName] #return to original addon directory os.chdir("../../../../Interface/AddOns/FaraFrames/") #open our saved variable file for merging toons a = open("../../../wtf/Account/ORETHLECROIX/SavedVariables/FaraFrames.lua","r"); toonList = []; toonList = parseLua(a) a.close() #initialize variables professions = {}; specs = {}; newList = {}; guildList = []; fullToonList = []; #crappy menu that will be removed option = 0 menu= {}; for server in fullList: print "%s. %s" %(option,server) menu[option] = server; option +=1 server = raw_input("which server? ") #retrieve guild information for each character on server chosen for character in fullList[menu[int(server)]]: characterSheet = getCharacterSheet(character,menu[int(server)]) if characterSheet != "fail": guild = getGuildName(characterSheet) print ("%s : %s\n" %(character,guild)) if (guild != "No Spec Information"): guildList.append(guild) else: print "FAILED" time.sleep(3) guildList = list(set(guildList)) #retrieve list of guild members for each guild retrieved in the previous block for guild in guildList: print "Getting Listing for %s" % guild guildMemberList = getGuildList(guild,menu[int(server)]) print guildMemberList time.sleep(3) fullToonList = list(set(fullToonList)|set(guildMemberList)) fullToonList.sort() guildMemberList = fullToonList guildMemberList.sort() #print guildList #for i in range(0,len(guildMemberList)): -- removed for testing purposes for i in range(0,10): currentToon = guildMemberList[i] #percent complete print "%0.4s%%" % float((i*100.0)/len(guildMemberList)) #print "%s/%s Guildmates" % ((i+1),len(guildList)) #retrieve charactersheet for current toon characterSheet = getCharacterSheet(currentToon,Realm) #gets professions for current toon professions[currentToon] = getProfessions(characterSheet) #get spec for current toon specs[currentToon] = getSpec(characterSheet) time.sleep(5) print "100.00%%" guildLen = len(guildMemberList) currentLine = 0; #print ("********************") obj={} for key in professions.keys(): #print key newList[key] = {} if professions.has_key(key): if professions[key] is not None: for innerkey in professions[key].keys(): #print innerkey newList[key][innerkey] = professions[key][innerkey]; for key in specs.keys(): if specs.has_key(key) : if specs[key] is not None: for innerkey in specs[key].keys(): #print innerkey newList[key][innerkey] = specs[key][innerkey]; print newList f = open("FaraFrames.lua","w"); f.write("function getD()\nreturn{") indexCount = 0; for key in newList.keys(): currentLine+=1 if newList[key].has_key("professions"): if newList[key]["professions"] != "No Information": #print "%s : %s" % (key,newList[key]["professions"]) spec = newList[key]["spec"] skillString = newList[key]["professions"] skillSets = skillString.split('|') firstSet = skillSets[0]; print firstSet secondSet = skillSets[1]; firstSet = firstSet.split(':') secondSet = secondSet.split(':') firstSkill = firstSet[0]; firstValue = firstSet[1]; secondSkill = secondSet[0]; secondValue = secondSet[1]; f.write('["%s"] = { %s = %s, %s = %s, Spec = "%s" }' % (key,firstSkill,firstValue,secondSkill,secondValue,spec)) indexCount +=1 if (currentLine < guildLen): f.write(",") #p.write("%s~%s~%s\n" % (key,newList[key]["professions"],spec)) else: print "%s does not have the key" f.write('}\nend\n') print "Indexed %s toons" % indexCount c = open("base.lua"); for line in c: f.write(line) f.close() a = open("../../../wtf/Account/ORETHLECROIX/SavedVariables/FaraFrames.lua","w"); a.write('\n') a.write("guildTools_toons = {\n") #print guildList for i in range(0,len(guildMemberList)): #print guildList[i] a.write('\t"%s",\n' % guildMemberList[i]) a.write("}") a.close() ''' guildTools_toons = { "Knikon", -- [1] "Acidbath", -- [2] } ''' ''' strAttributes = ( ('character','name',''), ( 'character', 'level',' Level '), ('character','race', ' '), ('character','class', ' '), ( 'character', 'guildName', ' | Member of: '), ( 'talentSpec','treeOne', ' | Spec: '), ( 'talentSpec','treeTwo','/'), ( 'talentSpec','treeThree','/'), ( 'skill','', ' ')) '''