X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=get_sgf;h=f978b81ed5c4a1321158bb88df40a98b58e37ab1;hb=dcce90e77c92202b5fadca48de6fd1cefc41ff79;hp=090ba8dcce4f199d7d0b48571db0e6ca2f8a5fe6;hpb=bd355978c5f8e326de6a4d32b7e8304a8192fd94;p=bin.git diff --git a/get_sgf b/get_sgf index 090ba8d..f978b81 100755 --- a/get_sgf +++ b/get_sgf @@ -113,6 +113,8 @@ my $base = 'http://gobase.org/online/sgf2misc/?fname=/games/japan/titles/kisei/3 for my $url (@ARGV) { # strip of leading stuff $url =~ s/[^=]+=//; + $url =~ s{(?:http://)?(?:gobase\.org)?}{}; + $url = qq(/$url) unless $url =~ m{^/}; my $fname = $url; my $uri = URI->new($base); $uri->query_form(mode => $options{mode}, @@ -121,13 +123,29 @@ for my $url (@ARGV) { $m->get("http://gobase.org$fname"); $m->save_content('temp.sgf'); $m->get($uri->as_string); + $m->follow_link(text_regex=>qr/PostScript/); $m->form_number(2); $m->select('scale',$options{scale}); $m->field('fig',$options{figures}); $m->select('paper',$options{paper}); $m->submit(); - $m->follow_link(url_regex=>qr/\.ps\.gz/); - $m->save_content('temp.ps.gz'); + my $content; + my $state; + my $sleep; + VALID_LOOP: { + do { + $state = $m->clone; + $m->follow_link(url_regex=>qr/\.ps\.gz/); + if ($m->content =~ /^\%\!PS/){ + $m->save_content('temp.ps'); + last VALID_LOOP; + } + $sleep = 240+int(rand()*120); + print STDERR "Failure to download content, waiting $sleep seconds\n"; + $m = $state; + } while (sleep $sleep); + } + system('gzip','temp.ps'); system("$ENV{HOME}/bin/sgf_rename",'temp.sgf'); }