You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.5 KiB

  1. <?php
  2. // It's Walky
  3. // Based on the Dumbing of Age script
  4. // We start with the current day, then click the Previous link until we find
  5. // an image we've already saved before.
  6. $html = file_get_contents('http://www.itswalky.com/');
  7. preg_match('@img src="http://www.itswalky.com/wp-content/uploads/(.+\\.png)@', $html, $matches);
  8. if (empty($matches[1])) {
  9. echo "No comic found on home page! :(\n";
  10. return;
  11. }
  12. if (!is_dir('itswalky')) {
  13. mkdir('itswalky');
  14. }
  15. // Download current page's comic, load previous comic webpage, repeat
  16. while (true) {
  17. $filename = basename($matches[1]);
  18. if (is_file('itswalky/' . $filename)) {
  19. return;
  20. }
  21. echo "Downloading {$filename}\n";
  22. $url = "http://www.itswalky.com/wp-content/uploads/{$matches[1]}";
  23. $data = @file_get_contents($url);
  24. if ($data) {
  25. file_put_contents("itswalky/{$filename}", $data);
  26. }
  27. // Find previous page link
  28. $regex = '@href="(http://www.itswalky.com/comic/[0-9a-zA-Z/-]+)" class="comic-nav-base comic-nav-previous"@';
  29. preg_match($regex, $html, $prevMatch);
  30. if (empty($prevMatch[1])) {
  31. echo "No previous URL found!\n";
  32. return;
  33. }
  34. $html = @file_get_contents($prevMatch[1]);
  35. if (!$html) {
  36. echo "Failed to load previous page!\n";
  37. return;
  38. }
  39. preg_match('@img src="http://www.itswalky.com/wp-content/uploads/(.+\\.png)@', $html, $matches);
  40. if (empty($matches[1])) {
  41. echo "No image found on page!\n";
  42. return;
  43. }
  44. usleep(5e5);
  45. }