Skip to content

Instantly share code, notes, and snippets.

@Avalarion
Created March 16, 2013 14:19
Show Gist options
  • Save Avalarion/5176579 to your computer and use it in GitHub Desktop.
Save Avalarion/5176579 to your computer and use it in GitHub Desktop.
<?php
/** A Game of Thrones **/
$links = array();
$links[] = 'http://awoiaf.westeros.org/index.php/A_Game_of_Thrones-Prologue';
for($i=1; $i<=72; $i++)
$links[] = 'http://awoiaf.westeros.org/index.php/A_Game_of_Thrones-Chapter_'.$i;
$links[] = 'http://awoiaf.westeros.org/index.php/A_Game_of_Thrones-Appendix';
$filename = '1_Game_of_Thrones';
getFiles($links, $filename);
/** A Clash of Kings **/
$links = array();
$links[] = 'http://awoiaf.westeros.org/index.php/A_Clash_of_Kings-Prologue';
for($i=1; $i<=69; $i++)
$links[] = 'http://awoiaf.westeros.org/index.php/A_Clash_of_Kings-Chapter_'.$i;
$links[] = 'http://awoiaf.westeros.org/index.php/A_Clash_of_Kings-Appendix';
$filename = '2_A_Clash_of_Kings';
getFiles($links, $filename);
/** A Storm of Swords **/
$links = array();
$links[] = 'http://awoiaf.westeros.org/index.php/A_Storm_of_Swords-Prologue';
for($i=1; $i<=80; $i++)
$links[] = 'http://awoiaf.westeros.org/index.php/A_Storm_of_Swords-Chapter_'.$i;
$links[] = 'http://awoiaf.westeros.org/index.php/A_Storm_of_Swords-Epilogue';
$links[] = 'http://awoiaf.westeros.org/index.php/A_Storm_of_Swords-Appendix';
$filename = '3_A_Storm_of_Swords';
getFiles($links, $filename);
/** A Feast for Crows **/
$links = array();
$links[] = 'http://awoiaf.westeros.org/index.php/A_Feast_for_Crows-Prologue';
for($i=1; $i<=45; $i++)
$links[] = 'http://awoiaf.westeros.org/index.php/A_Feast_for_Crows-Chapter_'.$i;
$links[] = 'http://awoiaf.westeros.org/index.php/A_Feast_for_Crows-Appendix';
$filename = '4_A_Feast_for_Crows';
getFiles($links, $filename);
/** A Dance with Dragons **/
$links = array();
$tmp = file_get_contents('http://awoiaf.westeros.org/index.php/Chapters_Table_of_contents#A_Dance_with_Dragons');
preg_match_all('/<table class="wikitable sortable">(.*?)<\/table>/ms', $tmp, $founds);
$found = $founds[1][4];
preg_match_all('/"(\/index.php\/.*?_\(A_Dance_with_Dragons\))"/', $found, $founds);
foreach($founds[1] as $found){
$links[] = 'http://awoiaf.westeros.org'.$found;
}
$filename = '5_A_Dance_with_Dragons';
getFiles($links, $filename);
function getFiles($links, $filename) {
$content = '';
foreach($links as $link){
$tmp = file_get_contents($link);
preg_match('/<\!-- content -->(.*?)<\!-- \/content -->/ms', $tmp, $founds);
$found = $founds[1];
$content .= $found;
}
$content .= '<style>.infobox, #jump-to-nav, .thumb{display:none;}</style>';
file_put_contents($filename.'.html', $content);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment