use DXUtil::month for sh/contest
[spider.git] / cmd / show / contest.pl
1 # contest.pl - contest calendar from www.sk3bg.se/contest
2 # used with 1 argument: sh/contest <yearandmonth>
3 # e g sh/contest 2002sep
4 # Tommy Johansson (SM3OSM) 2002-07-23
5 # New version using Net::Telnet  2003-03-09
6 #
7 #
8 #
9
10 my ($self, $line) = @_;
11
12 #return (1, "usage: sh/contest  <year_and_month>, e g sh/contest 2002sep ") unless $line;
13
14 my @out;
15
16 my $mon;;
17
18 # trying to make the syntax abit more user friendly...
19 # and yes, I have been here and it *is* all my fault (dirk)
20 $line = lc $line;
21 my ($m,$y) = $line =~ /^([a-z]+)\s*(\d+)/;
22 ($y,$m) = $line =~ /^(\d+)\s*([a-z]+)/ unless $y && $m;
23 unless ($y && $m) {
24         ($m,$y) = (gmtime)[4,5];
25         $m = lc $DXUtil::month[$m];
26         $y += 1900;
27 }
28 $y += 2000 if $y <= 50;
29 $y += 1900 if $y > 50 && $y <= 99;
30 $m = substr $m, 0, 3 if length $m > 3;
31 $m = 'oct' if $m eq 'okt';
32 $m = 'may' if $m eq 'mai' || $m eq 'maj';
33 $mon = "$y$m";
34
35 dbg($mon) if isdbg('contest');
36
37 my $filename = "c" . $mon . ".txt";
38 my $host = $Internet::contest_host || 'www.sk3bg.se';
39 my $port = 80;
40 my $url = $Internet::contest_url || "http://www.sk3bg.se/contest/text";
41 $url .= "/$filename";
42
43 my $t = new Net::Telnet (Telnetmode => 0);
44 eval {
45     $t->open(Host => $host, Port => $port, Timeout => 15);
46     };
47
48 if (!$t || $@) {
49     push @out, $self->msg('e18','sk3bg.se');
50 } else {
51     my $s = "GET $url";
52     $t->print($s);
53     my $notfound = $t->getline(Timeout => 10);
54     if ($notfound =~ /404 Object Not Found/) {
55             return (1, "there is no contest info for $mon")
56         } else {
57             push @out, $notfound;
58         }
59     while (!$t->eof) {
60         eval { 
61             push @out, $t->getline(Timeout => 10);
62         };
63         if ($@) {
64             push @out, $self->msg('e18', 'sk3bg.se');
65             last;    
66         }
67     }
68 }
69 $t->close;
70
71 return (1, @out);