Garfield comic strip downloader


This is a shell script that allows you to download Garfield comic strips from the official site.

Requirements



Tested on Linux, probably will work on other platforms supported by php-cli and wget as well. Your shell should support UTF-8 for this script to work flawlessly.

The script (version 1.0.2)


ckgarfdl.php (line 1)
  1. #!/usr/bin/php -q
  2.  
  3. <?php
  4.  
  5. $VeryFirstDay="19780619"; //the date of the first Garfield comic strip
  6. $CurrentDay=date("Ymd", strtotime("today")); //today
  7.  
  8. $PrintErrorMsg=False;
  9.  
  10. if(($_SERVER["argc"] <= 1) || (($_SERVER["argc"] == 2) && ($_SERVER["argv"][1] == "help")))
  11. {
  12.         print("Garfield comic strip downloader. Version 1.0.2 by Cyber Killer\n");
  13.         print("Get the latest version at http://digital.dharkness.info/CkGarfDl\n\n");
  14.         print("Usage:\n");
  15.         print("ckgarfdl.php help → print this text\n");
  16.         print("ckgarfdl.php all → gets all Garfield strips from the begining (1978-09-19) until today\n");
  17.         print("ckgarfdl.php <begin date> <end date> → gets all Garfield strips from the specified days\n");
  18.         print("                                       date should be in \"Ymd\" format e.g. 20100118 for 18th of January 2010\n");
  19.        
  20.         $IsOkayToDownload=False;
  21. }
  22. elseif($_SERVER["argc"] == 2)
  23. {
  24.         if($_SERVER["argv"][1] == "all")
  25.         {
  26.                 $StartDay=$VeryFirstDay;
  27.                 $EndDay=$CurrentDay;
  28.                 $IsOkayToDownload=True;
  29.         }
  30.         else
  31.         {
  32.                 $PrintErrorMsg=True;
  33.                 $IsOkayToDownload=False;
  34.         }
  35. }
  36. elseif($_SERVER["argc"] == 3)
  37. {
  38.         $StartDay=date("Ymd", strtotime($_SERVER["argv"][1]));
  39.         $EndDay=date("Ymd", strtotime($_SERVER["argv"][2]));
  40.         if((strcmp($StartDay, $VeryFirstDay) >= 0) && strcmp($EndDay, $CurrentDay) <= 0) //argument check
  41.         {
  42.                 $IsOkayToDownload=True;
  43.         }
  44.         else
  45.         {
  46.                 $PrintErrorMsg=True;
  47.                 $IsOkayToDownload=False;
  48.         }
  49. }
  50. elseif($_SERVER["argc"] > 3)
  51. {
  52.         $PrintErrorMsg=True;
  53.         $IsOkayToDownload=False;
  54. }
  55.  
  56. if($PrintErrorMsg==True)
  57. {
  58.         print("Syntax error!\n");
  59.         print("Try \"ckgarfdl.php help\" for help\n");
  60. }
  61.  
  62. if($IsOkayToDownload==True)
  63. {
  64.         $PlusDays = 0;
  65.         print("Starting download from " . $StartDay . " to " . $EndDay . "\n");
  66.         while((strcmp(date("Ymd", strtotime($StartDay . "+" . $PlusDays . " day")), date("Ymd", strtotime($EndDay)))) <= 0)
  67.         {
  68.                 system("wget http://images.ucomics.com/comics/ga/" .  date("Y", strtotime($StartDay . "+" . $PlusDays . " day")) . "/ga" . date("ymd", strtotime($StartDay . "+" . $PlusDays . " day")) . ".gif");
  69.                 $PlusDays++;
  70.         }
  71.         print("Download finished!\n");
  72.         print("Saved " . $PlusDays . " files.\n");
  73. }
  74.  
  75. ?>


Just click grab to save the file, or copy&paste it yourself to your favorite editor. Remember to add executable permissions.

License


CC-GNU GPL
This program is under the CC-GNU GPL, version 2.0 or later.

Garfield © 2007 Paws


 
CategoryProjekty

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki