]> git.donarmstrong.com Git - bin.git/blobdiff - get_sgf
track whether the ps downloaded is valid and compress it
[bin.git] / get_sgf
diff --git a/get_sgf b/get_sgf
index 090ba8dcce4f199d7d0b48571db0e6ca2f8a5fe6..973550d98fcc7312fd68a057e0b1204625c9fd38 100755 (executable)
--- 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},
@@ -126,8 +128,20 @@ for my $url (@ARGV) {
      $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;
+ 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;
+              }
+              $m = $state;
+         } while (sleep 30);
+     }
+     system('gzip','temp.ps');
      system("$ENV{HOME}/bin/sgf_rename",'temp.sgf');
 }