Change DXUser->get* to DXUser::get*
[spider.git] / cmd / show / grayline.pl
1 #!/usr/bin/perl
2 #
3 # show dawn, sunrise, sunset, and dusk times for each callsign or prefix entered
4 #
5
6 my ($self, $line) = @_;
7 my @f = split /\s+/, $line;
8
9 my @out;
10 my $f;
11 my $l;
12 my $n_offset;
13 my @list;
14
15 while ($f = shift @f){
16         if(!$n_offset){
17                 ($n_offset) = $f =~ /^([-+]?\d+)$/;
18                 next if $n_offset;
19         }
20         push @list, $f;
21 }
22 $n_offset = 0 unless defined $n_offset;
23 $n_offset = 0 if $n_offset > 365;  # can request moon rise/set up to 1 year ago or from now...
24 $n_offset = 0 if $n_offset < -365;
25
26 my ($lat, $lon);              # lats and longs in radians
27 my ($sec, $min, $hr, $day, $month, $yr) = (gmtime($main::systime+$n_offset*24*60*60))[0,1,2,3,4,5];
28
29 $month++;
30 $yr += 1900;
31
32 my @in;
33
34 if (@list) {
35         foreach $l (@list) {
36                 my $user = DXUser::get_current(uc $l);
37                 if ($user && $user->lat && $user->long) {
38                         push @in, [$user->qth, $user->lat, -$user->long, uc $l ];
39                 } else {
40                         # prefixes --->
41                         my @ans = Prefix::extract($l);
42                         next if !@ans;
43                         my $pre = shift @ans;
44                         my $a;
45                         foreach $a (@ans) {
46                                 $lat = $a->{lat};
47                                 $lon = -$a->{long};
48                                 push @in, [ $a->name, $lat, $lon, $pre ];
49                         }
50                 }
51         }
52 } else {
53         if ($self->user->lat && $self->user->long) {
54                 push @in, [$self->user->qth, $self->user->lat, -$self->user->long, $self->call ];
55         } else {
56                 push @in, [$main::myqth, $main::mylatitude, -$main::mylongitude, $main::mycall ];
57         }
58 }
59
60 push @out, $self->msg('grayline1');
61 push @out, $self->msg('grayline2');
62
63 foreach $l (@in) {
64         my ($dawn, $rise, $set, $dusk, $az, $dec )=Sun::rise_set($yr,$month,$day,$hr,$min,$l->[1],$l->[2],0);
65         $l->[3] =~ s{(-\d+|/\w+)$}{};
66         push @out,sprintf("%-6.6s %-30.30s %02d/%02d/%4d %s %s %s %s", $l->[3], $l->[0], $day, $month, $yr, $dawn, $rise, $set, $dusk);
67 }
68
69
70 return (1, @out);