-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros.pl
141 lines (131 loc) · 3.46 KB
/
ros.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/perl
# flags
# -a: active roster
# -i: inactive roster
# -n: number of players
# -p: picks
# -f: find player
# -B: batters only
# -P: batters only
# -A: all teams
# -L: page breaks
$username = 'ibl';
$dbname = ibl_stats;
$dobat = 1;
$dopit = 1;
$eol = '';
use DBI;
$dbh = DBI->connect("dbi:Pg:dbname=$dbname", "$username");
$loop = $dbh->prepare("select tig_name, comments, status, item_type
from teams where ibl_team = ? and item_type > 0
order by item_type, tig_name;");
while (@ARGV) {
if ( $last > 0 ) {
$last = 0;
printf "$eol\n";
}
$team = shift @ARGV;
if ( $team eq '-a' ) {
$loop = $dbh->prepare("select tig_name, comments, status, item_type
from teams where ibl_team = ? and item_type > 0
and status = 1 order by item_type, tig_name;");
next;
}
elsif ( $team eq '-i' ) {
$loop = $dbh->prepare("select tig_name, comments, status, item_type
from teams where ibl_team = ? and item_type > 0
and status > 1 order by item_type, tig_name;");
next;
}
elsif ( $team eq '-p' ) {
$loop = $dbh->prepare("select tig_name, comments, status, item_type
from teams where ibl_team = ? and item_type = 0
order by tig_name;");
next;
}
elsif ( $team eq '-f' ) {
$player = shift @ARGV;
$loop = $dbh->prepare("select ibl_team, tig_name, comments, status
from teams where tig_name ~* ?");
$loop->execute($player);
while ( @line = $loop->fetchrow_array ) {
( $team, $tigname, $how, $status ) = @line;
( $mlb, $name ) = split /\s/, $tigname, 2;
$name =~ s/ *$//;
$how =~ s/ *$//;
printf "%s %-3s %-3s %-20s %-40s\n",
($status == 1) ? '*' : ' ', $team, $mlb, $name, $how;
}
$last = 1;
next;
}
elsif ( $team eq '-c' ) {
$cards = 1;
next;
}
elsif ( $team eq '-n' ) {
$num = 1;
next;
}
elsif ( $team eq '-B' ) {
$dopit = 0;
next;
}
elsif ( $team eq '-P' ) {
$dobat = 0;
next;
}
elsif ( $team eq '-L' ) {
$eol = '';
next;
}
elsif ( $team eq '-A' ) {
$allteams = $dbh->selectcol_arrayref("select distinct(ibl_team) from teams where ibl_team != 'FA';");
push @ARGV, sort @$allteams;
next;
}
$team =~ tr/a-z/A-Z/;
$bnum = $pnum = 0;
$count = $loop->execute($team);
while ( @line = $loop->fetchrow_array ) {
( $tigname, $how, $status, $type ) = @line;
( $mlb, $name ) = split /\s/, $tigname, 2;
$name =~ s/ *$//;
$how =~ s/ *$//;
if ( $type > $last ) {
if ( $type == 1 && $dobat && $dopit ) { print "$team PITCHERS\n"; }
elsif ( $type == 2 && $dobat && $dopit ) { print "\n$team BATTERS\n"; }
$last = $type;
}
if ( $cards ) {
if ( $type == 1 && $dopit || $type == 2 && $dobat ) {
printf "%-3s %-15s ", $mlb, $name;
( $pname = $name ) =~ s/'/\./g;
if ( $type == 1 ) {
open( CARD, "card -wp $mlb.$pname | grep -v ^Player | cut -c 54- |" );
}
elsif ( $type == 2 ) {
open( CARD, "card -wb $mlb.$pname | grep -v ^Player | cut -c 50- |" );
}
while ( <CARD> ) {
( $h, $ob, $xb, $pwr ) = split;
printf "%4s%4s%4s%4s .", $h, $ob, $xb, $pwr;
}
close( CARD );
print "\n";
}
} else {
if ( $type == 0 || $type == 1 && $dopit || $type == 2 && $dobat ) {
printf "%s %-3s %-20s %-40s\n",
($status == 1) ? '*' : ' ', $mlb, $name, $how;
}
}
if ( $type == 1 ) { $pnum++; }
elsif ( $type == 2 ) { $bnum++; }
}
if ( $num == 1 && $count > 0 ) {
print "$team players: $count ($pnum pitchers, $bnum batters)\n";
}
}
QUIT:
$dbh->disconnect;