Sign in to follow this  
Followers 0
Marc

Downloading Comics

21 posts in this topic

Hi,

I suppose you'll consider me nuts, but I really did it: wrote a script which downloads the current strips from Garfield, Calvin & Hobbes and Dilbert.

Garfield and Calvin are easy, just have to calculate the filename from the current date and download it.

Dilbert is a real bitch, the filename is filled with other numbers by random, even the length can vary... so I just download the comic and give it a new name based on the current date without analysing the original name.

After downloading, the script moves the strips into the according directories

and checks for missing strips in these directories.

Note: there may not be any other files into these directories, otherwise the check routine will fail.

After moving, irfanview is called to show the new strips.

Global $dilbert

; some path settings
$irfanview     = "c:\programme\irfanview\i_view32.exe "
$pfad_calvin   = "d:\bilder\comics\calvin\1993\"
$pfad_garfield = "d:\bilder\comics\garfield\2004\"
$pfad_dilbert  = "d:\bilder\comics\dilbert\2004\"

$garfield = "ga" & StringRight(@year,2) & @mon & @mday & ".gif"
urldownloadtofile("http://images.ucomics.com/comics/ga/" & @year & "/" & $garfield,$garfield)

$calvin   = "ch" & StringRight(@year - 11,2) & @mon & @mday & ".gif"
urldownloadtofile("http://images.ucomics.com/comics/ch/" & @year - 11 & "/" & $calvin,$calvin)

Dilbert()

FileMove ($calvin,   $pfad_calvin)
FileMove ($garfield, $pfad_garfield)
FileMove ($dilbert,  $pfad_dilbert)

run ($irfanview & $pfad_calvin   & $calvin)
run ($irfanview & $pfad_garfield & $garfield)
run ($irfanview & $pfad_dilbert   & $dilbert)

pruefen($pfad_garfield)
pruefen($pfad_calvin)
pruefen($pfad_dilbert)


Func pruefen($pfad)

    local $fehlende
    local $schaltjahr
    local $monate[13]
    $monate[1] = 31
    $monate[2] = 29
    $monate[3] = 31
    $monate[4] = 30
    $monate[5] = 31
    $monate[6] = 30
    $monate[7] = 31
    $monate[8] = 31
    $monate[9] = 30
    $monate[10]= 31
    $monate[11]= 30
    $monate[12]= 31

    $fehlende=""

    $schaltjahr = StringMid($pfad,StringLen($pfad)-4,4)
    $schaltjahr = mod($schaltjahr,4)
    if $schaltjahr = 0 then
        $schaltjahr = 1
    else
        $schaltjahr = 0
    Endif

    $search = FileFindFirstFile($pfad & "*.*")
    If $search = -1 Then
        MsgBox(0, "Error", "No files/directories matched the search pattern")
        Exit
    EndIf
        $file = FileFindNextFile($search); "."
        $file = FileFindNextFile($search); ".."
        $file = FileFindNextFile($search)  

    $tag = 1
    $mon = 1
    While 1
        If @error Then ExitLoop
        $datei_mon = Int(StringMid($file,5,2))
        $datei_tag = Int(StringMid($file,7,2))
        if ($datei_tag<>$tag) or ($datei_mon<>$mon) then

           if ($schaltjahr = 0) and ($mon=2) and ($tag=29) then
           else
               $fehlende=$fehlende & $mon & "-" & $tag & @CRLF
           endif
        else
             $file = FileFindNextFile($search)
        endif

        $tag = $tag + 1
        if $tag > $monate[$mon] then
         $tag=1
         $mon = $mon+1
          if $mon>12 then ExitLoop
        EndIf
    WEnd
   ; Close the search handle
    FileClose($search)

    if $fehlende <>"" then Msgbox(0,$pfad, $fehlende)
EndFunc

Func Dilbert()
    urldownloadtofile("http://www.dilbert.com/comics/dilbert/archive/index.html","temp.dat")

    $file = FileOpen("temp.dat", 0)
    While 1
        $line = FileReadLine($file)
        $position = StringInStr($line,"Today's Dilbert Comic")
        If $position <>0 then ExitLoop
    Wend
    FileClose($file)
    FileRecycle ("temp.dat")

    $position2 = StringInStr($line,'<IMG SRC="/comics/dilbert/archive/images/')
    $position2 = $position2 + 41

    $datei = StringMid ($line, $position2, ($position-$position2)-16)

    $dilbert = "di" & StringRight(@year,2) & @mon & @mday & StringMid($datei,StringLen($datei)-3,4)

    urldownloadtofile("http://www.dilbert.com/comics/dilbert/archive/images/" & $datei,$dilbert)
EndFunc

Have fun with it :D

Marc


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites



Advice, change:

FileMove ($calvin, $pfad_calvin)

FileMove ($garfield, $pfad_garfield)

FileMove ($dilbert, $pfad_dilbert)

with

FileMove ($calvin, $pfad_calvin,1)

FileMove ($garfield, $pfad_garfield,1)

FileMove ($dilbert, $pfad_dilbert,1)

So if you start the script twice it will work all the same :D

Share this post


Link to post
Share on other sites

Indeed. Should have thought of that :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

I've tried to do the exact same thing, though not with the same comics..

Couldn't figure it out...

Link : Pondus

Share this post


Link to post
Share on other sites

checks for missing strips in these directories.

How this part should work?

I do not use the script everyday and it never downloaded comix I did not download...

Share this post


Link to post
Share on other sites

I do not use the script everyday and it never downloaded comix I did not download...

Retrieving the missing file is a different thing... currently it only checks for missing files and pops up a messagebox if there are any missing to the current date.

But its a good idea to add automatical downloads of missing parts, I'll give it a shot. :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

... and it never said that I were missing some comic... Really it seems that this pard of the script do not work.

Share this post


Link to post
Share on other sites

i tried it but it only gets me dilbert's comic... other files r created but corrupted.

Share this post


Link to post
Share on other sites

i've kind of figured the problem:

the other two 'cartoons' actually contained this:

<HTML>

<HEAD><TITLE>404 Not Found</TITLE></HEAD>

<BODY BGCOLOR="#cc9999" TEXT="#000000" LINK="#2020ff" VLINK="#4040cc">

<H2>404 Not Found</H2>

The requested URL '/comics/ch/1993/ch930416.gif' was not found on this server.

<HR>

<ADDRESS><A HREF="http://www.acme.com/software/thttpd/">thttpd/2.25b 29dec2003</A></ADDRESS>

</BODY>

</HTML>

and

<HTML>

<HEAD><TITLE>404 Not Found</TITLE></HEAD>

<BODY BGCOLOR="#cc9999" TEXT="#000000" LINK="#2020ff" VLINK="#4040cc">

<H2>404 Not Found</H2>

The requested URL '/comics/ga/2004/ga040416.gif' was not found on this server.

<HR>

<ADDRESS><A HREF="http://www.acme.com/software/thttpd/">thttpd/2.25b 29dec2003</A></ADDRESS>

</BODY>

</HTML>

Share this post


Link to post
Share on other sites

Hi Rathore,

since the script did/does work on my system, I' ve been amazed at your problem.

However, the quoted html file is really interesting, because the script tried to get

ch930416.gif which is really not on the server, because we have April, 15th not 16th.

So, does your pc have the correct time/date? Or perhaps you're living in a different time zone than the US Comics server? :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

@ezzetabi

Funny, you should get a messagebox. Just removed one of my comics and got this message as it should be :D

However, I have to admit that the logic how the missing files are checked is quite... stupid.

Could you tell me the directory names you're using and which comics are missing?

Hope this information will get me the neccessary enlightment, since I have not the slightest idea why the script stays silent. :huh2:


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

Or perhaps you're living in a different time zone than the US Comics server?

this was my guess too but i was reluctant to post it... can u make a change to the script where one can add (or less) hrs / mins to get it equal to gmt... then the script can autoconvert gmt to comic server's time. (the difference here will be stationary)

this will make ur script more 'global'.

Share this post


Link to post
Share on other sites

This is the script part where it sets folders...

$pfad_calvin = "C:\Download\Comix\Calvin"

$pfad_garfield = "C:\Download\Comix\Garfield"

$pfad_dilbert = "C:\Download\Comix\Dilbert"

Share this post


Link to post
Share on other sites

Couldn't check it yet (because I'm at work currently), but I suppose this is caused due to the missing Backslashes at the end.

Would you please try

$pfad_calvin = "C:\Download\Comix\Calvin\"

$pfad_garfield = "C:\Download\Comix\Garfield\"

$pfad_dilbert = "C:\Download\Comix\Dilbert\"

I'm excited to see what happens :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

if u don't plan to do the change i suggested, then plz just tell me what time zone applies at ur place...i'll make the necessary changes to script.

just dbl click the time in system tray -> time zone

tell me ur entry.

Share this post


Link to post
Share on other sites

Hi rathore,

I've been thinking about implementing this feature - not as easy as I'd like it to be.

My timezone is GMT +1 - good luck.

I fiddle arround with this, gonna see how far I get.


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

It works, you were right!

But I think you should adds a starting date and from that checking... I have a so long message that I cant see it all... !

Share this post


Link to post
Share on other sites

Ah, thats some relief :huh2:

About the starting date... hm, would be an option.

Currently I am thinking about putting all data in an array,

so it could be evalued before creating a messagebox.

Gonna see.. :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

Hiho,

here's another version which should download the missing files - if they are available.

Dilbert can be retrieved back for one month, Calvin and Garfield only 15 days.

Have fun...

Zip File

Made a short check, seems to work as it should :D


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

Hiho,

here's another version which should download the missing files - if they are available.

Dilbert can be retrieved back for one month, Calvin and Garfield only 15 days.

Have fun...

Zip File

Made a short check, seems to work as it should  :D

Hi Marc,

Check line 141, you can't have a comment character ";" on a line with the continuation character "_". It gives a missing "then" error.

Gene


[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0