#!/usr/bin/perl use warnings; use strict; $|=1; #my $url = "http://eve-central.com/dumps/"; #my $dir = "eve-central/"; #my $arch = "eve-central/arch/"; my ($url, $dir, $arch,); my $max = 3; my $necro = 0; use Getopt::Long qw(:config no_ignore_case bundling); GetOptions( 'u=s' => \$url, 'd=s' => \$dir, 'a=s' => \$arch, 'm=i' => \$max, 'n=i' => \$necro, ); die "no url" unless $url; $url =~ s,/*$,/,; die "no dir" unless $dir; $dir =~ s,/*$,/,; die "no such dir: $dir" unless -d $dir; $arch ||= $dir."arch"; $arch =~ s,/*$,/,; die "no such arch: $arch" unless -d $arch; use LWP::Simple; printf "Fetching %s ...", $url; my $r = LWP::Simple::get($url); printf " got %i byte\n", length($r); my %files = (); while ($r =~ s/href="(\d\d\d\d-\d\d-\d\d\.(dump\.gz|csv\.bz2))"//) { $files{$1}++; } my @want = (); my $old = ""; for my $f (sort keys %files) { # printf "CAND: %s ...", $f; die "bad file: $f" unless $f =~ /^(\d\d\d\d)-(\d\d)-/; if ($1 < 2010) { # printf " skipped veryold\n"; next; } if (-f $dir.$f || -f $arch.$f) { # printf " skipped have\n"; if ($necro && $old && !@want) { printf "NECRO: %s\n", $old; push @want, $old; $old = ""; } next; } if ($1 < 2011) { # && $2 < 6) { # printf " skipped old\n"; unless (@want) { $old = $f; } next; } push @want, $f; } for my $f (sort @want) { printf "WANT %s ...", $f; my $rc = LWP::Simple::mirror($url.$f, $dir.$f); printf " %s\n", $rc; last unless --$max; }