-
Notifications
You must be signed in to change notification settings - Fork 0
/
events_to_csv
executable file
·58 lines (50 loc) · 1.12 KB
/
events_to_csv
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
#!/usr/bin/env bash
#
# This script takes a directory containing some Retrosheet event log
# archives (eg: 2008ml.zip, 2007ml.zip) and loads all data into a CSV file
# via Chadwick. Specify the input directory and output file as arguments.
#
# You must have Chadwick's 'cwevent' utility properly installed. See:
# http://chadwick.sourceforge.net
#
# Retrosheet event logs can be downloaded from:
# http://www.retrosheet.org/game.htm
#
# Example usage:
# events_to_csv ~/eventlogs events.csv
#
show_usage() {
echo "Usage: events_to_csv INPUT_DIR [OUTPUT_FILE]"
}
# exit if no INTPUT_DIR given
if [[ -z "$1" ]]; then
show_usage
exit 1
else
if [[ -d "$1" ]]; then
zipdir="$1"
else
echo "Directory $1 not found"
exit 1
fi
fi
# choose a reasonable default OUTPUT_FILE if none given
if [[ -z "$2" ]]; then
outfile="$PWD/events.csv"
else
outfile="$PWD/$2"
fi
tmpdir="tmp$RANDOM"
# unzip archives to temp dir
cd "$zipdir"
unzip \*.zip -d "$tmpdir"
# run each event file through Chadwick
cd "$tmpdir"
for f in *.EV*; do
cwevent -f 0-96 -y ${f:0:4} $f >> "$outfile"
done
# clean up
rm *
cd ..
rmdir "$tmpdir"
exit 0