Last active
September 6, 2015 02:19
-
-
Save sagunms/9300036 to your computer and use it in GitHub Desktop.
Download edX Autonomous Mobile Robots (AMRx) Textbook to local.
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 | |
// Purpose: The edX AMR course textbook had extra large side buttons and very slow loading time, which was really annoying. | |
// For personal use only. | |
// Note: Create a directory ./book before running PHP script. | |
// Example: | |
// mkdir ./book # Create directory | |
// sudo chmod +w./book # Make the book directory writeable | |
// vim amr_textbook.php # Copy paste the following script, save, exit (:wq) | |
// php amr_textbook.php # Execute | |
$cnt = 1; | |
while($cnt < 474) { | |
$num_page = sprintf("%03d", $cnt++); | |
grab_image("https://s3.amazonaws.com/edx-textbooks/Siegwart--Autonomous+Mobile+Robots/p".$num_page.".png", "./book/p".$num_page.".png"); | |
} | |
// Aggregate all PNGs to a single PDF | |
// sudo apt-get install imagemagick # If you don't have ImageMagick installed | |
exec("convert ./book/*.png Amr2ndEdition.pdf"); | |
function grab_image($url,$saveto){ | |
$ch = curl_init ($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); | |
$raw = curl_exec($ch); | |
curl_close ($ch); | |
if(file_exists($saveto)) unlink($saveto); | |
$fp = fopen($saveto, 'x'); | |
fwrite($fp, $raw); | |
fclose($fp); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment