Better Warcraft Gear Script Version 2

Of course, you make one thing, then people come up with something better. That same guildie who is working on my robe, came back and said, "Why don't you just read the ingredients directly from Wowhead?".

OK, easy enough. Read from Wowhead, get reagents, recurse via loop. Two sources came in extremely handy for this. First WWoIT provided several excellent examples for reading from a web page, then Dan Sullivan provides this excellent XML in Powershell examples.

The final result is a bit more versatile than the last script.

Please Enter the WowHead ItemID (found in the URL)?: 42101
Ebonweave Robe x 1
  Ebonweave x 8
  Bolt of Imbued Frostweave x 8
   Bolt of Frostweave x 16
    Frostweave Cloth x 80
  Infinite Dust x 16
  Eternal Shadow x 16
 Bolt of Imbued Frostweave x 6
  Bolt of Frostweave x 12
   Frostweave Cloth x 60
  Infinite Dust x 12
 Eternium Thread x 1
 Frozen Orb x 1

So, here's the new and improved script:

function Read-URL ($url) {
#source: <a href="http://waynes-world-it.blogspot.com/2008/05/reading-web-content-with-powershell.html
" title="http://waynes-world-it.blogspot.com/2008/05/reading-web-content-with-powershell.html
">http://waynes-world-it.blogspot.com/2008/05/reading-web-content-with-pow...</a>       $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 get-ingredientfor([string]$item, [int]$multi) {
        $x +=4
        #$Needed = $csv | ?{$_.item -eq $item} 
        [xml] $needed = Read-URL($url+ $item + $strXML)
        Write-Host ("
" * $x) $needed.wowhead.item.name.psbase.innertext "x" $multi
        $reagents = $needed.wowhead.item.createdBy.spell.reagent
        if ($reagents -ne $null) {             
                $reagents | % {                        
                        if ($_.id -ne "
") {
                                get-ingredientfor $_.id ($multi * [int]$_.count)
                        } else {                                                               
                                #Write-Host ("
" * $x) "-" $needed.wowhead.item.class.psbase.innertext
                        }
                }
        } else {       
                #Write-Host ("
" * $x) "-" $needed.wowhead.item.class.psbase.innertext
        }
}

$x = -4
$url = "
http://www1.wowhead.com/?item="
#$itemCode = "
42101"
$strXML = "
&xml"
cls
Write-Host "
Beta - PowerShell World of Warcraft Ingredients List"
Write-Host "
This code will read the WowHead website and process all the ingredients necessary to make something."
Write-Host "
----------------------------------------------------------"
$ItemCode = Read-Host "
Please Enter the WowHead ItemID (found in the URL)?"

if ($itemcode -eq $null) {Throw "
Please enter an itemID to continue"}
$test = Read-URL($url+ $itemCode + $strXML)
if ($test -match "
not found") {Throw "Item not found in WowHead"}

get-ingredientfor $itemCode 1

Comments

Mechano-Hog Breakdown

Mechano-hog x 1
Titansteel Bar x 12
Titanium Bar x 36
- created
Eternal Fire x 12
- created
Eternal Earth x 12
- created
Eternal Shadow x 12
- created
Handful of Cobalt Bolts x 40
Cobalt Bar x 80
Cobalt Ore x 80
- drop
Arctic Fur x 2
- drop
- vendor
Salvaged Iron Golem Parts x 1
- vendor
Goblin-machined Piston x 8
- vendor
Elementium-plated Exhaust Pipe x 1
- vendor

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

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.