make sh/contest async
[spider.git] / cmd / show / contest.pl
index cb5b0a04705ff656cee51c8284b8d6f5958661c2..f29bbfe40d2214e3da83083637bfa425434d4d52 100644 (file)
@@ -4,7 +4,7 @@
 # Tommy Johansson (SM3OSM) 2002-07-23
 # New version using Net::Telnet  2003-03-09
 #
-# $Id$
+#
 #
 
 my ($self, $line) = @_;
@@ -13,20 +13,21 @@ my ($self, $line) = @_;
 
 my @out;
 
-my $mon;;
+my $mon;
 
 # trying to make the syntax abit more user friendly...
 # and yes, I have been here and it *is* all my fault (dirk)
 $line = lc $line;
-my ($m,$y) = $line =~ /^([a-z]{3})\w*\s*(\d+)/;
-($y,$m) = $line =~ /^(\d+)\s*([a-z]{3})/ unless $y && $m;
+my ($m,$y) = $line =~ /^([a-z]+)\s*(\d+)/;
+($y,$m) = $line =~ /^(\d+)\s*([a-z]+)/ unless $y && $m;
 unless ($y && $m) {
        ($m,$y) = (gmtime)[4,5];
-       $m = qw(jan feb mar apr may jun jul aug sep oct nov dec)[$m];
+       $m = lc $DXUtil::month[$m];
        $y += 1900;
 }
 $y += 2000 if $y <= 50;
 $y += 1900 if $y > 50 && $y <= 99;
+$m = substr $m, 0, 3 if length $m > 3;
 $m = 'oct' if $m eq 'okt';
 $m = 'may' if $m eq 'mai' || $m eq 'maj';
 $mon = "$y$m";
@@ -39,32 +40,22 @@ my $port = 80;
 my $url = $Internet::contest_url || "http://www.sk3bg.se/contest/text";
 $url .= "/$filename";
 
-my $t = new Net::Telnet (Telnetmode => 0);
-eval {
-    $t->open(Host => $host, Port => $port, Timeout => 15);
-    };
-
-if (!$t || $@) {
-    push @out, $self->msg('e18','sk3bg.se');
-} else {
-    my $s = "GET $url";
-    $t->print($s);
-    my $notfound = $t->getline(Timeout => 10);
-    if ($notfound =~ /404 Object Not Found/) {
-           return (1, "there is no contest info for $mon")
-       } else {
-           push @out, $notfound;
-       }
-    while (!$t->eof) {
-       eval { 
-           push @out, $t->getline(Timeout => 10);
-       };
-       if ($@) {
-           push @out, $self->msg('e18', 'sk3bg.se');
-           last;    
-       }
-    }
-}
-$t->close;
+push @out,  $self->msg('http1', 'sk3bg.se', "$filename");
+
+$self->http_get($host, $url, sub
+                               {
+                                       my ($response, $header, $body) = @_;
+                                       my @out;
+
+                                       if ($response =~ /^4/) {
+                                               push @out, "There is no contest info $mon";
+                                       } elsif ($response =~ /^5/) {
+                                               push @out, $self->msg('e18','sk3bg.se');
+                                       } else {
+                                               push @out, split /\r?\n/, $body;
+                                       }
+                                       $self->send_ans(@out);
+                               }
+                          );
 
 return (1, @out);