I am going to suggest a little different approach. Since downloading is an activity that is very prone to failure, I would maintain a list of downloads that need to be completed and break this operation into two processes: one would scan the list of downloads that need to be completed and then attempt to complete them; the other would add a new download task to the list every night (i.e. downloading last night's games.) The advantage of this is that in the event of a download failure, you can just run the first process again, and it will try to complete whatever download tasks failed.

The implementation can be very simple. Maintain two directories, unfinished/ and completed/. A download task can be represented by a file in unfinished/ whose name is the date of the desired download. When the download is complete, simply rename the file from the unfinished/ directory to the completed/ directory.

To add a download task, just create a new file in unfinished/ with the right name. This can be done via a cron job or even manually to redo a previous date.

Some more details...

Let's assume that the files in the unfinished/ directory have the form yyyy-mm-dd. Here's how to process each file:

opendir(D, "unfinished/") or die "unable to open unfinished/: $!\n"; my @files = readdir(D); closedir(D); for (@files) { next unless ($file =~ m/^(\d\d\d\d)-(\d\d)-(\d\d)$/); my ($year, $month, $day) = ($1, $2, $3); eval { ... process download for $year/$month/$day ... ... in case of an error, raise an exception with die ... }; if ($@) { warn "downloading for $year/$month/$date failed: $@\n"; } else { rename("unfinished/$file", "completed/$file"); } }
To create a new download task for yesterday's games:
my @t = localtime(time-86400); my $y = $t[5]+1900; my $m = $t[4]+1; my $d = $t[3]; my $file = sprintf("%04d-%02d-%02d", $y, $m, $d); open(F, ">", "unfinished/$file"); close(F);

In reply to Re: Help with Time by pc88mxer
in thread Help with Time by TheAnswer1313

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.