#!/usr/bin/python import sys, os, urllib2, urllib, os.path, datetime #import xml.dom.minidom import xml.etree.ElementTree as ET GUILD_NAME = 'Null' REALM = 'Maiev' outputDir = '/home/gregstoll/projects/wowarmory/data/' realmsInBattlegroup = ['Anub\'arak', 'Blackwater Raiders', 'Bladefist', 'Cenarion Circle', 'Cenarius', 'Darrowmere', 'Echo Isles', 'Fenris', 'Hyjal', 'Korialstrasz', 'Lightbringer', 'Maiev', 'Misha', 'Ravenholdt', 'Shu\'halo', 'Sisters of Elune', 'The Forgotten Coast', 'Uther', 'Vashj'] def main(): #testData = getCharacterData('Maiev', 'Tsouzer') charList = getGuildData(REALM, GUILD_NAME) #print "Characters in %s: %s" % (GUILD_NAME, charList) for name in charList: pathName = outputDir + name if (not os.path.exists(pathName)): os.mkdir(pathName) today = datetime.date.today() filename = pathName + '/' + today.isoformat() + '.xml' data = getCharacterData(REALM, name) outFile = open(filename, 'w') outFile.write(data) outFile.close() #et = ET.XML(testData) #print et.tag #charTag = et.find('characterInfo/character') #for key in charTag.attrib: # print "key: %s value: %s" % (key, charTag.attrib[key]) def getText(nodelist): rc = "" for node in nodelist: if node.nodeType == node.TEXT_NODE: rc = rc + node.data return rc def getArmoryData(req): req.add_header('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070220 Firefox/2.0.0.2') r = urllib2.urlopen(req) data = [] for line in r: data.append(line[:-1]) r.close() return '\n'.join(data) def getArenaTeamData(teamName): for realm in realmsInBattlegroup: data = getArmoryData(urllib2.Request('http://www.wowarmory.com/team-info.xml?%s' % urllib.urlencode([('r', realm), ('ts', 5), ('t', teamName), ('select', teamName)]))) et = ET.XML(data) team = et.find('teamInfo/arenaTeam') if (team.get('battleGroup') != None): return team def getCharacterData(realm, character, region='US'): # Test it manually here to avoid injection of some sort. prefix = 'us' if (region.lower() == 'eu'): prefix = 'eu' return getArmoryData(urllib2.Request('http://%s.wowarmory.com/character-sheet.xml?%s' % (prefix, urllib.urlencode([('r', realm), ('n', character)])))) def getCharacterTalentData(realm, character): return getArmoryData(urllib2.Request('http://www.wowarmory.com/character-talents.xml?%s' % urllib.urlencode([('r', realm), ('n', character)]))) def getGuildData(realm, guild): #return getArmoryData(urllib2.Request('http://armory.worldofwarcraft.com/guild-info.xml?%s' % urllib.urlencode([('r', realm), ('n', guild), ('p', 1)]))) curPage = 1 guildData = getArmoryData(urllib2.Request('http://armory.worldofwarcraft.com/guild-info.xml?%s' % urllib.urlencode([('r', realm), ('n', guild), ('p', curPage)]))) et = ET.XML(guildData) memberTag = et.find('guildInfo/guild/members') memberCount = int(memberTag.get('memberCount')) members = [x.get('name') for x in et.findall('guildInfo/guild/members/character')] while (len(members) < memberCount): curPage = curPage + 1 guildData = getArmoryData(urllib2.Request('http://armory.worldofwarcraft.com/guild-info.xml?%s' % urllib.urlencode([('r', realm), ('n', guild), ('p', curPage)]))) et = ET.XML(guildData) oldLen = len(members) for x in et.findall('guildInfo/guild/members/character'): members.append(x.get('name')) if (len(members) == oldLen): break return members def testItemInfo(realm, character): et = ET.XML(getCharacterData(realm, character)) itemIds = [] for x in et.findall('characterInfo/characterTab/items/item'): itemIds.append(int(x.get('id'))) spellHaste = 0 # TODO - correlate item ids with wowarmory?? return itemIds if (__name__ == '__main__'): main() #print testItemInfo('Maiev', 'Tsouzer') #print getCharacterData('Maiev', 'Tsouzer') #print getCharacterDataWithTalents('Maiev', 'Tsouzer')