All pastes #897766 Raw Edit

Mine

public python v1 · immutable
·published 2008-02-09 20:39 UTC
rendered paste body
# Interrogate wow armory import urllib2import xml.dom.minidomimport sysimport time#Imports realm information from config.wtfdef 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):	print "Getting information for %s..." % character	oDoc = getCharacterSheet(character,realm)	if oDoc != "fail":				element = 'skill';		attribute = '';		return getAttributes(oDoc,element,attribute);	else:		obj = {"professions":"No Information"}		return objdef 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 objRealm = getRealm()print Realmif Realm != "fail":	d = {};	Character = "Knikon"	oDoc = getCharacterSheet(Character,Realm)	myGuild = getGuildName(oDoc)	guildList = getGuildList(oDoc,Realm,myGuild);	guildList.sort()	for i in range(0,len(guildList)):				d[guildList[i]] = getProfessions(guildList[i],Realm)		time.sleep(1.5)		for key in d.keys():		if d[key].has_key("professions"):			print "%s : %s" % (key,d[key]["professions"])		else:			print "%s does not have the key"		else:	print "Realm Information Not Found" '''strAttributes = ( ('character','name',''),		( 'character', 'level',' Level '),                ('character','race', ' '),                ('character','class', ' '),                ( 'character', 'guildName', ' | Member of: '),                ( 'talentSpec','treeOne', ' | Spec: '),                ( 'talentSpec','treeTwo','/'),                ( 'talentSpec','treeThree','/'),		( 'skill','', ' '))'''