Created
July 26, 2017 19:08
-
-
Save KalleZ/2a5082253cc55cdeb975478bdfbd7eeb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
const API_KEY = 'XXX'; | |
function get_wow_item($id) | |
{ | |
$json = json_decode(file_get_contents('https://eu.api.battle.net/wow/item/' . $id . '?locale=en_GB&apikey=' . API_KEY)); | |
if($json->itemBind) | |
{ | |
return(false); | |
} | |
return($json->name); | |
} | |
function get_wow_pet_info($id) | |
{ | |
$json = json_decode(file_get_contents('https://eu.api.battle.net/wow/item/' . $id . '?locale=en_GB&apikey=' . API_KEY)); | |
if(!is_pet_cagable_wh($id)) | |
{ | |
return(false); | |
} | |
return($json->name); | |
} | |
function is_pet_cagable_wh($id) | |
{ | |
$html = file_get_contents('http://www.wowhead.com/item=' . $id); | |
if(($pos = strpos($html, '"modelviewer":')) == false) | |
{ | |
return(false); | |
} | |
return(strpos(file_get_contents('http://www.wowhead.com/npc=' . json_decode(substr($html, $pos + 14, strpos($html, '}', $pos + 15) - $pos - 13))->typeid), '\x5DNot\x20cageable') === false); | |
} | |
$ids = []; | |
$state = [ | |
'category' => '', | |
'ids' => '' | |
]; | |
/* tcg.txt is generated from some wget | grep magic */ | |
foreach(file('tcg.txt') as $line) | |
{ | |
if($line{0} === '|') | |
{ | |
if($state['category']) | |
{ | |
$ids[$state['category']] = $state['ids']; | |
} | |
$state['category'] = rtrim(substr($line, 1)); | |
$state['ids'] = []; | |
continue; | |
} | |
elseif(empty(trim($line)) || !$state['category'] || !is_numeric(rtrim($line))) | |
{ | |
continue; | |
} | |
$state['ids'][] = (integer) $line; | |
} | |
if($state['category']) | |
{ | |
$ids[$state['category']] = $state['ids']; | |
} | |
foreach($ids as $category => $cids) | |
{ | |
if($category == 'Pets (caged)') | |
{ | |
$cids = $ids['Pets (non-caged)']; | |
} | |
sort($cids); | |
$buffer = ''; | |
foreach($cids as $cid) | |
{ | |
if($category == 'Pets (caged)') | |
{ | |
$name = get_wow_pet_info($cid); | |
} | |
else | |
{ | |
$name = get_wow_item($cid); | |
} | |
if(!$name) | |
{ | |
continue; | |
} | |
$buffer .= sprintf('%d (%s)%s', $cid, $name, PHP_EOL); | |
} | |
if($buffer) | |
{ | |
printf('%s%s%s%s', $category, PHP_EOL, $buffer, PHP_EOL); | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|Mounts | |
49289 | |
54218 | |
23720 | |
49282 | |
69228 | |
54068 | |
71718 | |
72575 | |
93671 | |
49286 | |
49285 | |
68008 | |
72582 | |
79771 | |
68825 | |
49290 | |
54069 | |
49284 | |
49283 | |
|Toys | |
71628 | |
|Pets (non-caged) | |
72134 | |
35223 | |
72153 | |
93669 | |
67128 | |
71624 | |
79744 | |
68840 | |
68841 | |
32588 | |
23713 | |
34492 | |
34493 | |
49287 | |
38050 | |
49343 | |
71726 | |
67418 | |
46802 | |
106244 | |
39656 | |
20371 | |
|Pets (caged) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mounts | |
49282 (Big Battle Bear) | |
49283 (Reins of the Spectral Tiger) | |
49284 (Reins of the Swift Spectral Tiger) | |
49285 (X-51 Nether-Rocket) | |
49286 (X-51 Nether-Rocket X-TREME) | |
49290 (Magic Rooster Egg) | |
54068 (Wooly White Rhino) | |
54069 (Blazing Hippogryph) | |
68008 (Mottled Drake) | |
68825 (Amani Dragonhawk) | |
69228 (Savage Raptor) | |
71718 (Swift Shorestrider) | |
72575 (White Riding Camel) | |
72582 (Corrupted Hippogryph) | |
79771 (Feldrake) | |
93671 (Ghastly Charger's Skull) | |
Toys | |
71628 (Sack of Starfish) | |
Pets (caged) | |
23713 (Hippogryph Hatchling) | |
32588 (Banana Charm) | |
34492 (Rocket Chicken) | |
34493 (Dragon Kite) | |
38050 (Soul-Trader Beacon) | |
49287 (Tuskarr Kite) | |
49343 (Spectral Tiger Cub) | |
67128 (Landro's Lil' XT) | |
68840 (Landro's Lichling) | |
68841 (Nightsaber Cub) | |
71624 (Purple Puffer) | |
72134 (Grell Moss) | |
72153 (Sand Scarab) | |
79744 (Eye of the Legion) | |
93669 (Gusting Grimoire) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment