All pastes #898276 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-02-10 05:32 UTC
rendered paste body
# Interrogate wow armory
 
import urllib2
import xml.dom.minidom
import sys
import time

#Imports realm information from config.wtf
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):
	strUrl = "http://www.wowarmory.com/character-sheet.xml?r=%s&n=%s" % (realm.replace( ' ', '+'), character)
	#print "strUrl: " + 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
	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(character, realm):
	
	oDoc = getCharacterSheet(character,realm)
	if oDoc != "fail":
		
		element = 'skill';
		attribute = '';
		return getAttributes(oDoc,element,attribute);
	else:
		obj = {"professions":"No Information"}
		return obj

def getGuildList(oDoc,realm, guild):
	print guild
	members = [];
	strUrl = "http://www.wowarmory.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;



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:
		Elements = oDoc.getElementsByTagName(element)
		if len(Elements) > 0:
			oElement = oDoc.getElementsByTagName(element)[0]
			strValue = oElement.getAttribute(attribute)

	obj = {attribute : strValue}
	return obj


Realm = getRealm()

print Realm

if Realm != "fail":
	p = open("info.txt","w");
	f = open("FaraFrames.lua","w");
	f.write("function getD()\nreturn{")
	d = {};
	Character = "Knikon"
	oDoc = getCharacterSheet(Character,Realm)
	myGuild = getGuildName(oDoc)
	guildList = getGuildList(oDoc,Realm,myGuild);
	guildList.sort()
	for i in range(0,len(guildList)):
		print "%s/%s Guildmates" % ((i+1),len(guildList))
		d[guildList[i]] = getProfessions(guildList[i],Realm)
		time.sleep(1)
	
	guildLen = len(guildList)
	currentLine = 0;
	
	for key in d.keys():
		currentLine+=1
		if d[key].has_key("professions"):
			
			if d[key]["professions"] != "No Information":
				
				print "%s : %s" % (key,d[key]["professions"])
				skillString = d[key]["professions"]
				skillSets = skillString.split('|')	
	
				firstSet = skillSets[0];
				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 }' % (key,firstSkill,firstValue,secondSkill,secondValue))
				if (currentLine < guildLen):
					f.write(",")
				
				p.write("%s~%s\n" % (key,d[key]["professions"]))
		else:
			print "%s does not have the key"
	
	f.write('}\nend\n')
	
	c = open("base.lua");
	for line in c:
		f.write(line)
	f.close()

else:
	print "Realm Information Not Found"