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
|
#!/bin/bash
PROGNAME="$0"
usage() {
cat <<EOF
Usage:
`basename $PROGNAME` [options] [date] [cc]
Helper program to combine multiple pages of the bloomberg earnings
calendar into a single page.
Options:
-D lvl Debug level
EOF
exit 1
}
#
# Report an error and exit
#
error() {
echo "`basename $PROGNAME`: $1" >&2
exit 1
}
debug() {
if [ $DEBUG -ge $1 ]; then
echo "`basename $PROGNAME`: $2" >&2
fi
}
#
# Process the options
#
UA="Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
DEBUG=0
unset OPTIND
while getopts "D:h?" opt
do
case $opt in
D) DEBUG="$OPTARG";;
h|\?) usage;;
esac
done
shift `expr $OPTIND - 1`
case "$#" in
0) DATE=`date +"%Y%m%d"`; CC=US;;
1) DATE="$1"; CC=US;;
*) DATE="$1"; CC="$2";;
esac
#
# Main Program
#
#
# Retrieve one URL's worth, with retries
#
get1()
{
((i = 0))
while ((i < 3)); do
debug 1 "curl -s -m10 $URL > $TMP"
curl -m10 -s -A "$UA" $URL > $TMP
if [ -s $TMP ]; then
break
fi
((++i))
done
}
#http://quote.bloomberg.com/apps/ecal?c=US&date=20030722&strtpt=1&endpt=250
if [ $DEBUG = 0 ]; then
TMPBASE=/tmp/bloomearn.$$
else
TMPBASE=/tmp/bb
fi
#
# Fire off multiple requests to retrieve 25 lines at a time.
# If we request all the lines in 1 shot, the server gets very flaky
#
((amt = 25))
((sp = 1))
((ep = sp + amt - 1))
rm -f /tmp/bb.*
while ((sp < 500)); do
URL="http://quote.bloomberg.com/apps/ecal"
URL="$URL?date=$DATE"
URL="$URL&strtpt=$sp&endpt=$ep"
URL="$URL&c=$CC"
TMP=`printf "$TMPBASE.%03d\n" $sp`
get1 &
((sp += amt))
((ep += amt))
done
#
# Wait for all pages to be retrieved
#
wait
debug 1 "Done!"
#
# Output table header
#
cat <<EOF
<tr></tr>
<tr></tr>
<tr>
<td><b>COMPANY</b></td>
<td><b> SYMBOL</b></td>
<td><b>ANN. <br> DATE</b></td>
<td><b>PERIOD<br> ENDING</b></td>
<td><b>EST/ACTUAL EPS</b></td>
<td><b> AUDIO</b></td>
</tr>
EOF
#
# Massage and combine all of the pages into a single page
#
for i in $TMPBASE.*; do
sed < $i -e '1,/;COMPANY/d' -e '/style5Itlc/,$d' \
-e '/;NEXT&/d' -e '/>PREV&/d'
if ! grep -q ";NEXT" $i; then
break;
fi
done
if [ $DEBUG = 0 ]; then
rm -f $TMPBASE.*
fi
|