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.

49 lines
1.2 KiB

  1. <?php
  2. // Better Days
  3. // By Jay Naylor, completed in 2009. Custom site.
  4. $html = file_get_contents('http://jaynaylor.com/betterdays/');
  5. preg_match('@/betterdays/comic/(.+\\.(jpg|png|gif))@', $html, $matches);
  6. if (empty($matches[1])) {
  7. echo "No comic found on home page! :(\n";
  8. return;
  9. }
  10. if (!is_dir('betterdays')) {
  11. mkdir('betterdays');
  12. }
  13. // Download current page's comic, load previous comic webpage, repeat
  14. while (true) {
  15. echo "Downloading {$matches[1]}\n";
  16. $url = "http://jaynaylor.com/betterdays/comic/{$matches[1]}";
  17. $data = @file_get_contents($url);
  18. if ($data) {
  19. file_put_contents("betterdays/{$matches[1]}", $data);
  20. }
  21. // Find previous page link
  22. $regex = '@href="(http://jaynaylor.com/betterdays/archives/[0-9A-Za-z/_-]+\.html)">&laquo; Previous@';
  23. preg_match($regex, $html, $prevMatch);
  24. if (empty($prevMatch[1])) {
  25. echo "No previous URL found!\n";
  26. return;
  27. }
  28. $html = @file_get_contents($prevMatch[1]);
  29. if (!$html) {
  30. echo "Failed to load previous page!\n";
  31. return;
  32. }
  33. preg_match('@/betterdays/comic/(.+\\.(jpg|png|gif))@', $html, $matches);
  34. if (empty($matches[1])) {
  35. echo "No image found on page!\n";
  36. return;
  37. }
  38. usleep(5e5);
  39. }