Wikia

WoWWiki

Cisox/Scripts

Talk0
102,281pages on
this wiki

< User:Cisox

Most of my scripts are written in Perl or Python. I do all of my development in Linux, however, if you are going to run these in Windows you will need to download a version of Perl or Python for Windows. I would suggest Python.org or Active Python for Python on Windows, and Active Perl for Perl on Windows. I can't give any support for these packages, I just know they work.

item2wiki.plEdit

  • Language: Perl
  • Description: This script takes an item id (such as 30040) and generates code for the wiki page.
  • Example: perl item2wiki.pl 30040
  • Dependencies: XML::Simple, LWP
  • License: GPLv2
  • Updates:
    • I've created a website for the tool. Simply point your browser to http://odoshq.net/item2wiki.php?i=<itemid> and you will be presented with the wiki source of the item.
  • Quirks:
    • item_tooltip.xml from the Armory doesn't include all of the effects on items. I've tried getting this information from several sources, but they all either didn't have the information, was also missing the effect, or didn't have it in a usable state.
    • Not all of the tooltip properties are available in the sources I have. The solution to this problem is simply finding more item databases that can be exported to XML.


#!/usr/bin/perl
use XML::Simple;
use LWP;

my $usage = "Usage: <Item ID> [Verbose]\n";
my $itemid = shift or die $usage;
my $verbose = shift;

### Sources ###
my $armory_url = "http://armory.worldofwarcraft.com/item-tooltip.xml?i=$itemid";
my $ii_url = "http://armory.worldofwarcraft.com/item-info.xml?i=$itemid";
my $alk_url = "http://wow.allakhazam.com/cluster/item-xml.pl?witem=$itemid";

### Define Variables ###
my %tooltip = ('float'=>'right', 'width'=>'18em', 'itemid' => $itemid);
my %category_areas;
my $browser = LWP::UserAgent->new;
my @source;
my @categories;
my $disenchant;
my $class;

### Retrieve XML Data from Sources ###
verbose("Retrieving XML Data from Armory Item-Tooltip");
my $armory_response = $browser->get($armory_url,
	'Accept' => 'text/xml,application/xml,application/xhtml+xml;q=0.9,text/plain',
	'Accept-Language' => 'en-us;q=0.5',
	'Accept-Charset' => 'ISO-8559-1,utf-8;q=0.7,*;q=0.7',
	'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'
);

verbose("Retrieving XML Data from Armory Item-Info");
my $ii_response = $browser->get($ii_url,
	'Accept' => 'text/xml,application/xml,application/xhtml+xml;q=0.9,text/plain',
	'Accept-Language' => 'en-us;q=0.5',
	'Accept-Charset' => 'ISO-8559-1,utf-8;q=0.7,*;q=0.7',
	'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'
);

verbose("Retrieving XML Data from Allakhazam");
my $alk_response = $browser->get($alk_url,
	'Accept' => 'text/xml,application/xml,application/xhtml+xml;q=0.9,text/plain',
	'Accept-Language' => 'en-us;q=0.5',
	'Accept-Charset' => 'ISO-8559-1,utf-8;q=0.7,*;q=0.7',
	'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'
);

my $armory_content = $armory_response->content;
my $ii_content = $ii_response->content;
my $alk_content = $alk_response->content;

### Define Pre-Defined Variables ###
my @quality = ('Poor', 'Common', 'Uncommon', 'Rare', 'Epic', 'Legendary');
my @bind = ('', 'BoP', 'BoE', 'BoU', 'Quest');
my @slots = ('Non-Equip', 'Head', 'Neck', 'Shoulders', 'Shirt', 'Chest', 'Waist', 'Legs', 'Feet', 'Wrist', 'Hand', 'Finger', 'Trinket', 'One-Hand', 'Off Hand', 'Ranged', 'Back', 'Two-Hand', 'Bag', 'Tabard', 'Main Hand', 'Off Hand', 'Held in Off Hand', 'Projectile', 'Thrown', 'Ranged', 'Quiver', 'Relic');
my @dmgtype = ('', 'Holy', 'Fire', 'Nature', 'Frost', 'Shadow', 'Arcane');
my @attributes = ('bonusStrength', 'bonusAgility', 'bonusStamina', 'bonusIntellect', 'bonusSpirit', 'fireResist', 'natureResist', 'frostResist', 'shadowResist', 'arcaneResist');
my %attributes_hash = ('bonusStrength' => 'Strength', 'bonusAgility' => 'Agility', 'bonusStamina' => 'Stamina', 'bonusIntellect' => 'Intellect', 'bonusSpirit' => 'Spirit', 'fireResist' => 'Fire Resistance', 'natureResist' => 'Nature Resistance', 'frostResist' => 'Frost Resistance', 'shadowResist' => 'Shadow Resistance', 'arcaneResist' => 'Arcane Resistance');
my @weapon_plural = ('Axe' => 'Axes', 'Bow' => 'Bows', 'Crossbow' => 'Crossbows', 'Fishing Pole' => 'Fishing Poles', 'Fist Weapon' => 'Fist Weapons', 'Gun' => 'Guns', 'Mace' => 'Maces', 'Polearm' => 'Polearms', 'Staff' => 'Staves', 'Sword' => 'Swords', 'Dagger' => 'Daggers', 'Thrown' => 'Thrown Weapons', 'Wand' => 'Wands');
my @reputation = ('Hated', 'Hostile', 'Unfriendly', 'Neutral', 'Friendly', 'Honored', 'Revered', 'Exalted');
my @triggers = ('Use', 'Equip', 'Chance on Hit');
my @dropRate = ('None', 'Rare', 'Low', 'Medium', 'High', 'Guaranteed');
my @classes = ('', 'Container', 'Weapon', 'Gem', 'Armor', 'Reagent', 'Projectile', 'Trade Goods', '', 'Recipe', '', 'Quiver', 'Quest', 'Key', '', 'Miscellaneous');
my @classification = ('', 'Elite', 'Rare Elite', 'Boss', 'Rare');

### Start Parsing Data ###
verbose("Parsing Item");
my $xml = new XML::Simple;
my $armory_data = $xml->XMLin($armory_content, 'SuppressEmpty' => undef);
my $ii_data = $xml->XMLin($ii_content, 'SuppressEmpty' => undef);
my $alk_data = $xml->XMLin($alk_content, 'SuppressEmpty' => undef);

my $item_tooltip = $armory_data->{'itemTooltips'}->{'itemTooltip'};
my $ii_item = $ii_data->{'itemInfo'}->{'item'};

### Parse Icon ###
verbose("Icon");
my @sp = split(/\//, $alk_data->{'icon'});
my $icon = pop(@sp);
my @sp = split(/\./, $icon);
my $icon = shift(@sp);
$tooltip{'icon'} = $icon;

### Parse Stack ###
verbose("Stack");
if($item_tooltip->{'stackable'})
{
	$tooltip{'stack'} = $item_tooltip->{'stackable'};
}

### Parse Name ###
verbose("Name");
$tooltip{'name'} = $item_tooltip->{'name'};

### Parse Quality ###
verbose("Quality");
$tooltip{'quality'} = $quality[$item_tooltip->{'overallQualityId'}];
push(@categories, $tooltip{'quality'} . " Items");

### Parse Bind and QItem ###
verbose("Bind & QItem");
if(defined($item_tooltip->{'bonding'}))
{
	if($item_tooltip->{'bonding'} eq "4")
	{
		$tooltip{'qitem'} = 1;
	}
	else
	{
		if($item_tooltip->{'bonding'} ne "0")
		{
			$tooltip{'bind'} = $bind[$item_tooltip->{'bonding'}];
		}
	}
}

### Parse Duration ###
verbose("Duration");
### Not Stored in Sources ###

### Parse Unique and Unique-EQ ###
verbose("Unique & Unique-EQ");
if(defined($item_tooltip->{'maxCount'}))
{
	if(ref($item_tooltip->{'maxCount'}) eq "ARRAY")
	{
		$tooltip{'unique'} = "";
	}
	else
	{
		if($item_tooltip->{'maxCount'}->{'content'})
		{
			$tooltip{'unique'} = $item_tooltip->{'maxCount'}->{'content'};
		}

		if($item_tooltip->{'maxCount'}->{'uniqueEquippable'})
		{
			$tooltip{'unique-eq'} = 1;
		}
	}
}
	
### Parse QBegin ###
verbose("QBegin");
if(defined($item_tooltip->{'startQuestId'}))
{
	$tooltip{'qbegin'} = 1;
}

### Parse Type, Slot, and Bag ###
verbose("Type & Slot & Bag");
if(defined($item_tooltip->{'equipData'}))
{
	if(defined($item_tooltip->{'equipData'}->{'subclassName'}))
	{
		$tooltip{'type'} = $item_tooltip->{'equipData'}->{'subclassName'};
	}

	if(defined($item_tooltip->{'equipData'}->{'inventoryType'}))
	{
		if($item_tooltip->{'equipData'}->{'inventoryType'} eq "18")
		{
			$tooltip{'bag'} = $item_tooltip->{'equipData'}->{'containerSlots'};
		}
		elsif($item_tooltip->{'equipData'}->{'inventoryType'} ne "0")
		{
			if($item_tooltip->{'classId'} eq "6")
			{
				$tooltip{'slot'} = "Projectile";
			}
			else
			{
				$tooltip{'slot'} = $slots[$item_tooltip->{'equipData'}->{'inventoryType'}];
			}
		}
	}

	### Weapon ###
	if($item_tooltip->{'classId'} eq "2")
	{
		push(@categories, $weapon_plural{$tooltip{'type'}});
	}

	### Armor ###
	if($item_tooltip->{'classId'} eq "4")
	{
		push(@categories, $tooltip{'type'} . " Armor");
		push(@categories, "Armor:" . $tooltip{'slot'});
	}
}
	
### Parse Speed, Dmg, DmgType, Bonus, BonusType, and DPS ###
verbose("Speed & Dmg & DmgType & Bonus & BonusType & DPS");
if(defined($item_tooltip->{'damageData'}))
{
	if(defined($item_tooltip->{'damageData'}->{'speed'}))
	{
		$tooltip{'speed'} = $item_tooltip->{'damageData'}->{'speed'};
	}

	if(defined($item_tooltip->{'damageData'}->{'damage'}))
	{
		$tooltip{'dmg'} = $item_tooltip->{'damageData'}->{'damage'}->{'min'} . " - " . $item_tooltip->{'damageData'}->{'damage'}->{'max'};
		$tooltip{'dmgtype'} = $dmgtype[$item_tooltip->{'damageData'}->{'damage'}->{'type'}];
	}

	if(defined($item_tooltip->{'damageData'}->{'dps'}))
	{
		$tooltip{'dps'} = $item_tooltip->{'damageData'}->{'dps'};
	}
}

### Parse Armor ###
verbose("Armor");
if(defined($item_tooltip->{'armor'}) && $item_tooltip->{'armor'} > 0)
{
	$tooltip{'armor'} = $item_tooltip->{'armor'};
}	

### Parse InstanceBind ###
verbose("InstanceBind");
if(defined($item_tooltip->{'instanceBound'}))
{
	$tooltip{'instancebind'} = $item_tooltip->{'instancebind'};
}

### Parse Block ###
verbose("Block");
if(defined($item_tooltip->{'blockValue'}) && $item_tooltip->{'blockValue'} > 0)
{
	$tooltip{'block'} = $item_tooltip->{'blockValue'};
}

### Parse Attrib ###
verbose("Attrib");
my $attribs = "";
foreach $attribute (@attributes)
{
	if(defined($item_tooltip->{"$attribute"}))
	{
		my $modifier = "";
		if($item_tooltip->{"$attribute"} > 0)
		{
			$modifier = "+";
		}

		if($attribs ne "")
		{
			$attribs .= "<br />";
		}
		$attribs .= "$modifier" . $item_tooltip->{"$attribute"} . " [[" . $attributes_hash{$attribute} . "]]";
	}
}

if($attribs ne "")
{
	$tooltip{'attrib'} = $attribs;
}

### Parse Req ###
verbose("Req");
### Need Example ###

### Parse Sockets and Sockbonus ###
verbose("Sockets & Sockbonus");
if(defined($item_tooltip->{'socketData'}))
{
	push(@categories, "Socketed Items");

	if(defined($item_tooltip->{'socketData'}->{'socketMatchEnchant'}))
	{
		$tooltip{'sockbonus'} = $item_tooltip->{'socketData'}->{'socketMatchEnchant'};
	}

	my $sockets = "";
	my $socket_ref = scalar($item_tooltip->{'socketData'}->{'socket'});
	my @sockets_arr = @$socket_ref;

	foreach $socket (@sockets_arr)
	{
		if($sockets ne "")
		{
			$sockets .= "<br />";
		}
		$sockets .= "{{Socket|" . $socket->{'color'} . "}}";
	}
	$tooltip{'sockets'} = $sockets;
}
		
### Parse Durability ###
verbose("Durability");
if(defined($item_tooltip->{'durability'}))
{
	$tooltip{'durability'} = $item_tooltip->{'durability'}->{'max'};
}

### Parse Locked ###
verbose("Locked");
### Not Stored in Sources ###

### Parse Races ###
verbose("Races");
if(defined($item_tooltip->{'allowableRaces'}))
{
	if(ref($item_tooltip->{'allowableRaces'}->{'race'}) == "ARRAY")
	{
		my $races = "";
		my $race_ref = scalar($item_tooltip->{'allowableRaces'}->{'race'});
		my @race_arr = @$race_ref;
		foreach $race (@race_arr)
		{
			if($races ne "")
			{
				$races .= ", ";
			}
			$races .= $race;
		}
		$tooltip{'races'} = $races;
	}
	else
	{
		$tooltip{'races'} = $item_tooltip->{'allowableRaces'}->{'race'};
	}
}
		
### Parse Classes ###
verbose("Classes");
if(defined($item_tooltip->{'allowableClasses'}))
{
	if(ref($item_tooltip->{'allowableClasses'}->{'class'}) == "ARRAY")
	{
		my $classes = "";
		my $class_ref = scalar($item_tooltip->{'allowableClasses'}->{'sclass'});
		my @class_arr = @$class_ref;

		foreach $class (@class_arr)
		{
			if($classes ne "")
			{
				$classes .= ", ";
			}
			$classes .= $class;
		}
		$tooltip{'classes'} = $classes;
	}
	else
	{
		$tooltip{'classes'} = $item_tooltip->{'allowableClasses'}->{'class'};
	}
}

### Parse Rep and RFaction ###
verbose("Rep & RFaction");
if(defined($item_tooltip->{'requiredFaction'}))
{
	$tooltip{'rep'} = $reputation[$item_tooltip->{'requiredFaction'}->{'rep'}];
	$tooltip{'rfaction'} = $item_tooltip->{'requiredFaction'}->{'name'};
}

### Parse Skill ###
verbose("Skill");
if(defined($item_tooltip->{'requiredAbility'}))
{
	$tooltip{'skill'} = $item_tooltip->{'requiredAbility'};
}

### Parse Level ###
verbose("Level");
if(defined($item_tooltip->{'requiredLevel'}) && $item_tooltip->{'requiredLevel'} ne "1")
{
	$tooltip{'level'} = $item_tooltip->{'requiredLevel'};
}

### Parse Create, CreateEQ, and Mats ###
if(defined($ii_item->{'plansFor'}))
{
	$tooltip{'create'} = $ii_item->{'plansFor'}->{'spell'}->{'item'}->{'name'};
	$tooltip{'createeq'} = $quality[$ii_item->{'plansFor'}->{'spell'}->{'item'}->{'quality'}];

	if(defined($ii_item->{'plansFor'}->{'spell'}->{'reagent'}->{'name'}))
	{
		$tooltip{'mats'} = "[[" . $ii_item->{'plansFor'}->{'spell'}->{'reagent'}->{'name'} . "]] (" . $ii_item->{'plansFor'}->{'spell'}->{'reagent'}->{'count'} . ")";
	}
	else
	{
		my $mats = "";
		my $reagent_ref = scalar($ii_item->{'plansFor'}->{'spell'}->{'reagent'});
		my %reagent_hash = %$reagent_ref;
		my @reagent_keys = keys(%reagent_hash);
		foreach $reagent (@reagent_keys)
		{
			if($mats ne "")
			{
				$mats .= ", ";
			}
			$mats .= "[[$reagent]] (" . $reagent_hash{$reagent}->{'count'} . ")";
		}
		$tooltip{'mats'} = $mats;
	}

	my $requiredSkill = $ii_item->{'requiredSkill'};
	if($requiredSkill eq "Alchemy")
	{
		push(@categories, "Alchemy Recipe");
	}
	elsif($requiredSkill eq "Blacksmithing")
	{
		push(@categories, "Blacksmithing Plans");
	}
	elsif($requiredSkill eq "Enchanting")
	{
		push(@categories, "Enchanting Recipes");
	}
	elsif($requiredSkill eq "Leatherworking")
	{
		push(@categories, "Leatherworking Patterns");
	}
	elsif($requiredSkill eq "Tailoring")
	{
		push(@categories, "Tailoring Patterns");
	}
	elsif($requiredSkill eq "Jewelcrafting")
	{
		push(@categories, "Jewelcrafting Designs");
	}
	elsif($requiredSkill eq "Engineering")
	{
		push(@categories, "Engineering Schematics");
	}
	elsif($requiredSkill eq "Fishing")
	{
		push(@categories, "Fishing");
	}
	elsif($requiredSkill eq "First Aid")
	{
		push(@categories, "First Aid");
	}
	elsif($requiredSkill eq "Cooking")
	{
		push(@categories, "Cooking");
	}
}

### Parse Effect ###
verbose("Effect & Create & CreateEQ & Mats");
if(defined($item_tooltip->{'spellData'}))
{
	if(ref($item_tooltip->{'spellData'}->{'spell'}) eq "ARRAY")
	{
		my $effects = "";
		my $effect_ref = scalar($item_tooltip->{'spellData'}->{'spell'});
		my @effect_arr = @$effect_ref;

		foreach $effect (@effect_arr)
		{
			if($effects ne "")
			{
				$effects .= "<br />";
			}
			$effects .= $triggers[$effect->{'trigger'}] . ": " . $effect->{'desc'};

			if(defined($effect->{'charges'}))
			{
				$tooltip->{'charge'} = $effect->{'charges'};
			}
		}

		$tooltip{'effect'} = $effects;
	}
	else
	{
		$tooltip{'effect'} = $triggers[$item_tooltip->{'spellData'}->{'spell'}->{'trigger'}] . ": " . $item_tooltip->{'spellData'}->{'spell'}->{'desc'};

		if(defined($item_tooltip->{'spellData'}->{'spell'}->{'charges'}))
		{
			$tooltip->{'charge'} = $item_tooltip->{'spellData'}->{'spell'}->{'charges'};
		}
	}
}

### Parse Comment ###
verbose("Comment");
if(defined($item_tooltip->{'desc'}))
{
	$tooltip{'comment'} = $item_tooltip->{'desc'};
}

### Parse Desc ###
verbose("Desc");
### Need Example ###

### Parse Cooldown ###
verbose("Cooldown");
### Not Stored in Sources ###

### Parse Cast ###
verbose("Cast");
### Not Stored in Sources ###

### Parse ILvl ###
verbose("ILvl");
if(defined($ii_item->{'level'}))
{
	$tooltip{'ilvl'} = $ii_item->{'level'};
}

### Parse Source ###
verbose("Source");
if(defined($ii_item->{'createdBy'}))
{
	$tooltip{'source'} = "Created";
	$sources{'createdBy'} =	"Created by [[" . $ii_item->{'createdBy'}->{'spell'}->{'item'}->{'name'} . "]]";

	my $requiredSkill = $ii_item->{'createdBy'}->{'spell'}->{'item'}->{'requiredSkill'};
	if($requiredSkill eq "Alchemy")
	{
		push(@categories, "Alchemy Products");
		if($tooltip{'name'} =~ /Potion/)
		{
			push(@categories, "Potions");
		}
	}
	elsif($requiredSkill eq "Blacksmithing")
	{
		push(@categories, "Blacksmithing Products");
	}
	elsif($requiredSkill eq "Enchanting")
	{
		push(@categories, "Enchanting Products");
	}
	elsif($requiredSkill eq "Leatherworking")
	{
		push(@categories, "Leatherworking Products");
	}
	elsif($requiredSkill eq "Tailoring")
	{
		push(@categories, "Tailoring Products");
	}
	elsif($requiredSkill eq "Jewelcrafting")
	{
		push(@categories, "Jewelcrafting Products");
	}
	elsif($requiredSkill eq "Engineering")
	{
		push(@categories, "Engineering Products");
	}
	elsif($requiredSkill eq "First Aid")
	{
		push(@categories, "First Aid Products")
	}
	elsif($requiredSkill eq "Cooking")
	{
		push(@categories, "Cooking Products");
	}
}

if(defined($ii_item->{'dropCreatures'}))
{
	$tooltip{'source'} = "Drop";
	if(defined($ii_item->{'dropCreatures'}->{'creature'}->{'id'}))
	{
		my $level;
		if($ii_item->{'dropCreatures'}->{'creature'}->{'minLevel'} == $ii_item->{'dropCreatures'}->{'creature'}->{'maxLevel'})
		{
			$level = $ii_item->{'dropCreatures'}->{'creature'}->{'maxLevel'};
		}
		else
		{
			$level = $ii_item->{'dropCreatures'}->{'creature'}->{'minLevel'} . " - " . $ii_item->{'dropCreatures'}->{'creature'}->{'maxLevel'};
		}

		if($ii_item->{'dropCreatures'}->{'creature'}->{'classification'} ne "0")
		{
			$level .= " " . $classification[$ii_item->{'dropCreatures'}->{'creature'}->{'classification'}];
		}

		my $area = $ii_item->{'dropCreatures'}->{'creature'}->{'area'};
		$area =~ s/^The //g;
		$area =~ s/-/ /g;

		my $heroic = "";
		if(defined($ii_item->{'dropCreatures'}->{'creature'}->{'heroic'}))
		{
			$heroic = " (Heroic)";
		}

		$sources{'dropCreatures'} = "Dropped by Level $level [[" . $ii_item->{'dropCreatures'}->{'creature'}->{'name'} . "]] - [[$area]]$heroic - " . $dropRate[$ii_item->{'dropCreatures'}->{'creature'}->{'dropRate'}] . "<br />\n";
		$category_areas{$area} = 1;

	}
	else
	{
		my $creatures = "Dropped by:<br />\n";
		my $creatures_ref = scalar($ii_item->{'dropCreatures'}->{'creature'});
		my %creatures_hash = %$creatures_ref;
		my @creatures_keys = sort {$creatures_hash{$a}->{'area'} cmp $creatures_hash{$b}->{'area'} || $a cmp $b} keys(%creatures_hash);
	
		foreach $creature (@creatures_keys)
		{	
			my $level;
			if($creatures_hash{$creature}->{'minLevel'} == $creatures_hash{$creature}->{'maxLevel'})
			{
				$level = $creatures_hash{$creature}->{'maxLevel'};
			}
			else
			{
				$level = $creatures_hash{$creature}->{'minLevel'} . " - " . $creatures_hash{$creature}->{'maxLevel'};
			}

		if($creatures_hash{$creature}->{'classification'} ne "0")
		{
			$level .= " " . $classification[$creatures_hash{$creature}->{'classification'}];
		}


			my $area = $creatures_hash{$creature}->{'area'};
			$area =~ s/^The //g;
			$area =~ s/-/ /g;

			my $heroic = "";
			if(defined($creatures_hash{$creature}->{'heroic'}))
			{
				$heroic = " (Heroic)";
			}

			$creatures .= "Level $level [[$creature]] - [[$area]]$heroic - " . $dropRate[$creatures_hash{$creature}->{'dropRate'}] . "<br />\n";
			$category_areas{$area} = 1;
		}
		$sources{'dropCreatures'} = $creatures;
	}
}

if(defined($ii_item->{'rewardFromQuests'}))
{
	$tooltip{'source'} = "Quest";
	push(@categories, "Quest Rewards");

	if(defined($ii_item->{'rewardFromQuests'}->{'quest'}->{'name'}))
	{
		$sources{'rewardFromQuests'} = "Quest Reward From {{quest|" . $ii_item->{'rewardFromQuests'}->{'quest'}->{'name'} . "|" . $ii_item->{'rewardFromQuests'}->{'quest'}->{'name'} . "}}<br />\n";
	}
	else
	{
		my $quests = "Quest Reward From:<br />\n";
		my $quests_ref = scalar($ii_item->{'rewardFromQuests'}->{'quest'});
		my %quests_hash = %$quests_ref;
		my @quests_keys = keys(%quests_hash);
		foreach $quest (@quests_keys)
		{		
			$quests .= "{{quest|$quest|$quest}}<br />\n";
		}
		$sources{'rewardFromQuests'} = $quests;
	}
}

if(defined($ii_item->{'vendors'}))
{
	$tooltip{'source'} = "Vendor";
	if(defined($ii_item->{'vendors'}->{'creature'}->{'name'}))
	{
		$sources{'vendor'} = "Sold by [[" . $ii_item->{'vendors'}->{'creature'}->{'name'} . "]] in [[" . $ii_item->{'vendors'}->{'creature'}->{'area'} . "]]<br />\n";
	}
	else
	{
		my $vendors = "Sold by:<br />\n";
		my $vendors_ref = scalar($ii_item->{'vendors'}->{'creature'});
		my %vendors_hash = %$vendors_ref;
		my @vendors_keys = keys(%vendors_hash);
		foreach $vendor (@vendors_keys)
		{		
			$vendors .= "[[$vendor]] in [[" . $vendors_hash{$vendor}->{'area'} . "]]<br />\n";
		}
		$sources{'vendor'} = $vendors;
	}
}

### Parse Disenchant ###
verbose("Disenchant");
if(defined($ii_item->{'disenchantLoot'}))
{
	if(defined($ii_item->{'disenchantLoot'}->{'item'}->{'icon'}))
	{
		my $count = "1";

		if($ii_item->{'disenchantLoot'}->{'item'}->{'minCount'} == $ii_item->{'disenchantLoot'}->{'item'}->{'maxCount'})
		{
			$count = $ii_item->{'disenchantLoot'}->{'item'}->{'maxCount'};
		}
		else
		{
			$count = $ii_item->{'disenchantLoot'}->{'item'}->{'minCount'} . " - " . $ii_item->{'disenchantLoot'}->{'item'}->{'maxCount'};
		}

		$disenchant = "Requires Level " . $ii_item->{'disenchantLoot'}->{'requiredSkillRank'} . " [[Enchanting]]<br />\n";
		$disenchant .= "$count" . "x{{loot|" . $quality[$ii_item->{'disenchantLoot'}->{'item'}->{'quality'}] . "|" . $ii_item->{'disenchantLoot'}->{'item'}->{'name'} . "}} (" . $dropRate[$ii_item->{'disenchantLoot'}->{'item'}->{'dropRate'}] . ")<br />\n";
	}
	else
	{
		my $items = "";
		my $items_ref = scalar($ii_item->{'disenchantLoot'}->{'item'});
		my %items_hash = %$items_ref;
		my @items_keys = keys(%items_hash);
		foreach $item (@items_keys)
		{
			my $count = "1";

			if($items_hash{$item}->{'minCount'} == $items_hash{$item}->{'maxCount'})
			{
				$count = $items_hash{$item}->{'maxCount'};
			}
			else
			{
				$count = $items_hash{$item}->{'minCount'} . " - " . $items_hash{$item}->{'maxCount'};
			}
			$items .= "$count" . "x{{loot|" . $quality[$items_hash{$item}->{'quality'}] . "|$item}} (" . $dropRate[$items_hash{$item}->{'dropRate'}] . ")<br />\n";
		}

		$disenchant = "Requires Level " . $ii_item->{'disenchantLoot'}->{'requiredSkillRank'} . " [[Enchanting]]<br />\n$items";
	}
}

### Parse Sell ###
verbose("Sell");
### Not Stored in Sources ###

### Parse Sell and Vendor ###
verbose("Sell & Vendor");
if(defined($ii_item->{'cost'}))
{
	if(defined($ii_item->{'cost'}->{'token'}))
	{
		my $token_item = item_lookup($ii_item->{'cost'}->{'token'}->{'id'});
		my $token = $token_item->{'name'};	
		
		$tooltip{'vendor'} = $ii_item->{'cost'}->{'token'}->{'count'} . "x[[$token]]";
	}

	if(defined($ii_item->{'cost'}->{'sellPrice'}))
	{
		my @sp = split(//, $ii_item->{'cost'}->{'sellPrice'});
		
		my $temp = pop(@sp);
		my $copper = pop(@sp) . $temp;
	
		my $temp = pop(@sp);
		my $silver = pop(@sp) . $temp;
	
		my $gold = join(//, @sp);
	
		if(!defined($gold))
		{
			$gold = "0";
		}
	
		if(!defined($silver))
		{
			$silver = "0";
		}
	
		if(!defined($copper))
		{
			$copper = "0";
		}
	
		$tooltip{'sell'} = "{{cost|$gold|$silver|$copper}}";
	}

	if(defined($ii_item->{'cost'}->{'buyPrice'}))
	{
		my @sp = split(//, $ii_item->{'cost'}->{'buyPrice'});
		
		my $temp = pop(@sp);
		my $copper = pop(@sp) . $temp;
	
		my $temp = pop(@sp);
		my $silver = pop(@sp) . $temp;
	
		my $gold = join(//, @sp);
	
		if(!defined($gold))
		{
			$gold = "0";
		}
	
		if(!defined($silver))
		{
			$silver = "0";
		}
	
		if(!defined($copper))
		{
			$copper = "0";
		}
	
		$tooltip{'vendor'} = "{{cost|$gold|$silver|$copper}}";
	}
}

### Categories ###
### Instance ###
if(scalar(keys(%category_areas)) > 0)
{
	my @category_area_keys = sort{$a cmp $b} keys(%category_areas);
	foreach $area (@category_area_keys)
	{
		push(@categories, "Instance:$area");
	}
}

### Output Results ###
### Print Header ###
print("<noinclude>__NOTOC__</noinclude>\n\n");

### Print Tooltip ###
print("{{Tooltip\n");

my @tooltip_keys = sort{$a cmp $b} keys(%tooltip);
foreach $key (@tooltip_keys)
{
	print("|$key=" . $tooltip{$key} . "\n");
}

print("}}\n\n");
print("<noinclude>\n");
### Print Source ###
print("==Source==\n");
if(defined($sources{'createdBy'}))
{
	print($sources{'createdBy'} . "\n");
}

if(defined($sources{'rewardFromQuests'}))
{
	print($sources{'rewardFromQuests'} . "\n");
}

if(defined($sources{'dropCreatures'}))
{
	print($sources{'dropCreatures'} . "\n");
}

if(defined($sources{'vendor'}))
{
	print($sources{'vendor'} . "\n");
}

print("\n");

### Print Disenchant ###
if($disenchant ne "")
{
	print("==Disenchants into==\n$disenchant\n\n");
}

### Print External links ###
print("==External links==\n");
print("{{elinks-item|$itemid}}\n\n");

### Print Categories ###
foreach $category (@categories)
{
	print("[[Category:$category]]\n");
}

print("</noinclude>\n");

sub verbose()
{
	my $message = shift(@_);
	if(defined($verbose))
	{
		print(STDERR "# $message\n");
	}
}

sub item_lookup()
{
	my $id = shift(@_);
	my $item_url = "http://armory.worldofwarcraft.com/item-tooltip.xml?i=$id";
	my $item_response = $browser->get($item_url,
		'Accept' => 'text/xml,application/xml,application/xhtml+xml;q=0.9,text/plain',
		'Accept-Language' => 'en-us;q=0.5',
		'Accept-Charset' => 'ISO-8559-1,utf-8;q=0.7,*;q=0.7',
		'User-Agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'
	);

	my $item_content = $item_response->content;
	my $item_data = $xml->XMLin($item_content, 'SuppressEmpty' => undef);
	my $item = $item_data->{'itemTooltips'}->{'itemTooltip'};
	return $item;
}

Around Wikia's network

Random Wiki