1
#!/usr/local/bin/perl -w
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
24
25
use LWP::Simple;
26
use IO::Socket;
27
28
use Geo::METAR;
29
my $m = new Geo::METAR;
30
31
my $wx = getmetar('KORD');
32
setdisplay($wx, '169.254.10.10');
33
34
sub getmetar {
35
my $icao = shift;
36
my $page = get("http://weather.noaa.gov/cgi-bin/mgetmetar.pl?cccc=$icao") or exit;
37
38
$page =~ /($icao .+)/;
39
my $report = $1;
40
41
$m->metar($report);
42
43
my $wx;
44
$wx = " WEATHER CONDITIONS ";
45
46
47
48
my $temp = $m->TEMP_F."F/".$m->TEMP_C."C";
49
my $pad = (20 - length $temp)/2;
50
$wx .= " " x $pad.$temp." " x $pad;
51
52
my $vis = $m->VISIBILITY;
53
$vis =~ /(\d+)/;
54
my $atmos = "visibility $1 mi.";
55
$pad = (20 - length $atmos)/2;
56
$wx .= " " x $pad.$atmos." " x $pad;
57
58
my $wspd = $m->WIND_MPH;
59
my $wind = "Wind $wspd mph";
60
$pad = (20 - length $wind)/2;
61
$wx .= " " x $pad.$wind." " x $pad;
62
63
return $wx;
64
65
}
66
67
sub setdisplay {
68
69
my $rdymsg = shift; my $peeraddr = shift;
70
my $socket = IO::Socket::INET->new(
71
PeerAddr => $peeraddr,
72
PeerPort => "9100",
73
Proto => "tcp",
74
Type => SOCK_STREAM
75
) or die "Could not create socket: $!";
76
77
my $data = <<EOJ
78
\e%-12345X\@PJL JOB
79
\@PJL RDYMSG DISPLAY="$rdymsg"
80
\@PJL EOJ
81
\e%-12345X
82
EOJ
83
;
84
85
print $socket $data;
86
87
}