]> 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 229424c0b3849c1dd838f5ab7690a14820809285..973550d98fcc7312fd68a057e0b1204625c9fd38 100755 (executable)
--- a/get_sgf
+++ b/get_sgf
@@ -128,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');
 }