Grab my WoW Character into Powershell (aka case study in pulling data from xml)

I've always believed the best way to learn scripting is to build a script that you immediately have a need want for. For example, I was reading through one of my Warlock forums for World of Warcraft on a flowchart describing gem selection for gear. OMG, That's great, but well, I want to change it, I want to automate it. So, let's fire up the Powershell!

At first glance, this is going to be EASY! Read the armory, get gems, review counts and then spit out the data. Second glance at the wowarmory data, a lot of information is embedded in cdata fields; data that I immediately wanted and need! Data like what is the gemming requirements on the meta-gem, or what the socket bonus is for my dagger.

The following function reads my toons data directly from the WowArmory, then pulls the items statistics from Wowhead. This builds an object containing my personal details and the statistics for those items.

Example:
Armor : {Conqueror's Deathbringer Hood, Evoker's Charm...}
prefix :
factionId : 1
battleGroup : Shadowburn
lastModified : November 17, 2009
points : 4785
name : Elkagorasa
realm : Malfurion
guildName : Order of Thought
suffix : the Noble
race : Orc
class : Warlock
raceId : 2
guildUrl : r=Malfurion&gn=Order+of+Thought
genderId : 0
charUrl : r=Malfurion&n=Elkagorasa
titleId : 122
classId : 9
classUrl : c=Warlock
level : 80
gender : Male
faction : Horde

If you expand the Armor Property, here's my belt:
id : 41898
gem0Id : 40125
gem1Id : 40113
gem2Id : 0
durability : 35
maxDurability : 35
permanentenchant : 0
randomPropertiesId : 0
itemid : 41898
Name : Furious Gladiator's Cord of Dominance
slotbak : 6
displayid : 59294
reqlevel : 80
classes : 400
reqrep : 5
armor : 177
socket1 : 8
socketbonus : 2872
critstrkrtng : 48
resirtng : 56
splpwr : 90
sta : 96
int : 42
dura : 35
nsockets : 1
reqarenartng : 1450

Now, I'd like to find a way to lookup the "socketbonus" id to determine what that translates to. I am considering looping through, say everyone in guild to get their socket bonus (the detailed explanation is in an armor cdata field) and see if the value breaks down into something easier.

So for now, my primary objective is at a standstill, but I now have the data to work from.

function Read-URL ($url) {
#source: http://waynes-world-it.blogspot.com/2008/05/reading-web-content-with-powershell.html
        $col = new-object System.Collections.Specialized.NameValueCollection
        $col.Add("a","stats")
        $col.Add("s","s451qaz2WSX")
        $wc = new-object system.net.WebClient
        $wc.proxy = $proxy
        $wc.QueryString = $col
        $webpage = $wc.DownloadData($url)
        $string = [System.Text.Encoding]::ASCII.GetString($webpage)
        return $String
}

function Retrieve-WOWToon ([string] $Realm, [string]$ToonName) {
        #Static pointers to Wowhead to extract item stats.
        $WowHeadurl = "http://www.wowhead.com/?item="
        $strXML = "&xml"

        #URL to wowarmory page.
        $url = "http://www.wowarmory.com/character-sheet.xml?r=$Realm&n=$ToonName"

        #Uses Get-Web from the
        $xmldoc = Get-Web $url
       
        #Populate all character info on tab.
        $Details = $xmldoc.html.page.characterInfo.character

        #Grab gear collection from server
        $ArmorArr = @()
        $gear = $xmldoc.html.page.characterInfo.characterTab.items.item
        foreach ($armor in $gear) {
                #Populate properties from each item to post on armor property
                $result = $armor | select ID, Gem*, *Durability, permanentenchant,randompropertiesID

                #Read from Wowhead to get details on item.
                $itemPath = $WowHeadurl + $armor.id + $strXML
                [xml] $ArmorItem = Read-url $ItemPath
                $armorstats = $armorItem.wowhead.item.jsonequip.get_FirstChild().get_data().split(",")
                $result | Add-Member -memberType NoteProperty -name itemid -value $armor.id
                $result | Add-Member -memberType NoteProperty -name Name -value $armorItem.wowhead.item.name.get_FirstChild().get_data()

                #populates statistics on item, like what would trigger user.
                foreach ($Stat in $armorStats) {
                        $statArr = $stat.split(":")
                        $result = Add-Member -inputobject $result -memberType NoteProperty -name $statArr[0] -value $statArr[1]  -passThru
                }
                $armorArr += $result
        }
        #http://blogs.msdn.com/powershell/archive/2009/11/03/workaround-for-add-member-on-plain-net-objects.aspx
        $Details = Add-Member -in $details -memberType noteproperty -name Armor -value $armorArr -passThru
        $user = $details
        return $user
}

$Toon = Retrieve-WowToon "Malfurion" "Elkagorasa"

Comments

Best place comprar viagra

Best place comprar viagra

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options