Skip to content

Commit

Permalink
hacky script to update quest categories from wowhead JS
Browse files Browse the repository at this point in the history
  • Loading branch information
iamcal committed Dec 9, 2011
1 parent c25e9c4 commit 633cd55
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions cron/quest_cats.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?
include(dirname(__FILE__).'/../include/init.php');

#
# fetch JS file
#

$url = escapeshellarg('http://wowjs.zamimg.com/js/locale_enus.js?'.time());
$data = shell_exec("wget -q -O - $url");


#
# parse it out into variable assignments
#

$all = array();
$chunks = explode('var ', $data);
foreach ($chunks as $chunk){
$chunk = preg_replace('!;\s*!', '', $chunk);
list($name, $json) = explode('=', $chunk, 2);
$all[$name] = $json;
}


#
# reformat JSON to be valid
#

$json = $all['mn_quests'];
$json = str_replace(',,', ',0,', $json);
$json = str_replace('[,', '[0,', $json);

$obj = JSON_decode($json);


#
# extract flat list of categories
#

$out = array();

foreach ($obj as $cat){

if (is_array($cat[3]) && count($cat[3])){

$sub_cats = array();
foreach ($cat[3] as $sub){
$sub_cats[$sub[0]] = $sub[1];
}

$out[$cat[1]] = $sub_cats;
}
}


#
# insert into DB
#

db_query("DELETE FROM guild_quests_cats");
$order = 1;
foreach ($out as $cat => $rows){
foreach ($rows as $id => $name){

db_insert('guild_quests_cats', array(
'id' => intval($id),
'name' => AddSlashes($name),
'cat_name' => AddSlashes($cat),
'in_order' => $order,
));

$order++;
}
}

$num = count($out);
echo "Inserted $num cats\n";


?>

0 comments on commit 633cd55

Please sign in to comment.