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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
#!/bin/bash
#
# Helper to run the ProphetFinance.com ChartStream applet
#
# Will also run the money.net flavor of the same applet
# if passed -m as the first option.
#
#
# Width and height of applet window.
#
WIDTH=700
HEIGHT=350
USERNAME=Guest
PASSWORD=Guest
UA="Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)"
PATH=$PATH:$HOME/bin:/usr/share/linuxtrade/bin
LT=$HOME/.linuxtrade
TMP=$LT/tmp.pf
RC=$LT/rc
# Which site to use, the old prophetfinace.com site, or the new
# prophet.net site. TODO: need to key "key" value for new site,
# also, support javachart.
SITE=old
SITE=new
APPLET=javachart.applet
APPLET=chartstream.applet
#
# Get username, password, and geometry
#
geom=
while read tag eq val
do
case "$tag" in
pf_user) USERNAME="$val";;
pf_pass) PASSWORD="$val";;
lc_geom) geom="$val";;
esac
done < $RC
if [ "$USERNAME" = "Guest" ]; then
SCHEME=DEFAULTDNQ
CODEBASE=delayed
NOADS=false
else
SCHEME=DEFAULTRNQ
CODEBASE=realtime
NOADS=true
fi
if [ "$geom" != "" ]; then
w=`echo "$geom" | sed -e 's/[ xX].*//' -e 's/[^0-9]*//g' `
h=`echo "$geom" | sed -e 's/.*[ xX]//' -e 's/[^0-9]*//g' `
if [ "0$w" -ge 200 ]; then WIDTH=$w; fi
if [ "0$h" -ge 200 ]; then HEIGHT=$h; fi
fi
#
# Process the options
#
FLAVOR=prophet
FRESH=0
DEBUG=0
unset OPTIND
while getopts "monjfrw:h:p:u:D:h?" opt
do
case $opt in
m)
while read tag eq val
do
case "$tag" in
username)
if [ "$val" != demouser ]; then
USERNAME="$val\$NET";
SCHEME=MONEYNET
CODEBASE=realtime
NOADS=true
fi
;;
esac
done < $LT/money.net
;;
o) SITE=old; APPLET=chartstream.applet;;
n) SITE=new;;
j) APPLET=javachart.applet;;
f) FRESH=1;;
h) HEIGHT="$OPTARG";;
w) WIDTH="$OPTARG";;
u) touch $RC; USERNAME="$OPTARG";;
p) touch $RC; PASSWORD="$OPTARG";;
r) touch $RC;; # refresh
D) DEBUG="$OPTARG";;
h|\?) usage;;
esac
done
shift `expr $OPTIND - 1`
#
# Authenticate and get the livecharts applet
#
COOKIES=$LT/pf.cookies
authenticate() {
touch -d yesterday $TMP
if [ ! -s $COOKIES -o $RC -nt $COOKIES -o $COOKIES -ot $TMP ]; then
curl -A "$UA" -s \
-c $COOKIES \
-d "username=$USERNAME" \
-d "password=$PASSWORD" \
-d "login=Sign+In" \
http://www.prophet.net/forms/signin.jsp \
> /dev/null
fi
}
get_applet() {
#
# GET java applet page
#
case "${SITE}-${APPLET}" in
old-*) curl -L -A "$UA" -s -o$TMP \
"http://www.prophetfinance.com/charts/chartstream.asp"
;;
new-c*)
authenticate
# Get page with the applet
curl -A "$UA" -s -b $COOKIES -o$TMP \
"http://www.prophet.net/analyze/chartstream.jsp"
;;
new-j*)
authenticate
curl -A "$UA" -s -b $COOKIES -o$TMP \
"http://www.prophet.net/analyze/javacharts.jsp"
;;
esac
sed -n '/<applet/,/<\/applet/p' < $TMP > $LT/$APPLET
}
#
# If the rc file had changed, or the applet launch page is older than
# 1 day, then get a new copy of the applet launch page
#
case "${SITE}-${APPLET}" in
old-*)
touch -d yesterday $TMP
if [ ! -s $LT/$APPLET -o $RC -nt $LT/$APPLET -o $LT/$APPLET -ot $TMP ]; then
curl -L -A "$UA" -s -o$TMP \
"http://www.prophetfinance.com/charts/chartstream.asp"
sed -n '/<applet/,/<\/applet/p' < $TMP > $LT/$APPLET
fi
;;
new-c*)
authenticate
# Always get page with the applet, we need a unique key
curl -A "$UA" -s -b $COOKIES -o$TMP \
"http://www.prophet.net/analyze/chartstream.jsp"
sed -n '/<applet/,/<\/applet/p' < $TMP > $LT/$APPLET
;;
new-j*)
authenticate
# Always get page with the applet, we need a unique key
curl -A "$UA" -s -b $COOKIES -o$TMP \
"http://www.prophet.net/analyze/javacharts.jsp"
sed -n '/<applet/,/<\/applet/p' < $TMP > $LT/$APPLET
;;
esac
#touch -d yesterday $TMP
#if [ ! -s $LT/$APPLET -o $RC -nt $LT/$APPLET -o $LT/$APPLET -ot $TMP ]; then
# get_applet
#fi
#
# Change to temp dir
#
cd $LT || exit 1
#
# If there is a local jar file, run that
#
FLAGS=
if [ -f ChartStream.jar -a "$FRESH" != 1 ]; then
cat <<-EOF > prophet.policy
grant {
permission java.net.SocketPermission
"developer", "resolve";
permission java.lang.RuntimePermission
"accessClassInPackage.sun.misc";
permission java.net.SocketPermission
"$CODEBASE.prophetfinance.com",
"connect,accept,resolve";
};
EOF
ORIGBASE=`sed -n < prophet.applet 's/.*codebase="\([^\"]*\)"/\1/p' `
sed < $APPLET > tmp.0 \
-e "s/codebase=\"[^\"]*\"//" \
-e "s@VIEWASTEXT>@&<param name=\"origcodebase\" value=\"$ORIGBASE\">@"
APPLET=tmp.0
FLAGS="-s"
SCHEME=DEFAULTRNQ
fi
#
# For each symbol on the command line, fire up a chart
#
UCUSERNAME=`echo "$USERNAME" | tr '[a-z]' '[A-Z]'`
>pf.log
((i=1))
for sym in "$@"
do
#
# convert canonical index names to Lycos index names
#
case "$sym" in
'$DJI') sym='$INDU';;
'$DJT') sym='$TRAN';;
'$DJU') sym="$sym";;
'$COMP') sym='$COMPX';;
'$TRIN') sym='$TRIN';;
'$TICK') sym='$TICK';;
'$TRINQ') sym='$TRINQ';;
'$'*) sym="$sym.x";;
esac
sed < $APPLET > tmp.$i \
-e "/name=\"symbol\"/s/value=\".*\"/value=\"$sym\"/" \
-e "/name=\"username\"/s/value=\".*\"/value=\"$UCUSERNAME\"/" \
-e "/name=\"detachlet\"/s/value=\".*\"/value=\"true\"/" \
-e "s/.INDU/$sym/" \
-e "s/width=\"[^\"]*\"/width=\"$WIDTH\"/" \
-e "s/height=\"[^\"]*\"/height=\"$HEIGHT\"/" \
-e "s/delayed/$CODEBASE/" \
-e "s/Guest/$USERNAME/" \
-e "s/DEFAULTDNQ/$SCHEME/" \
-e "s/640/$WIDTH/" \
-e "s/480/$HEIGHT/" \
-e "s/VIEWASTEXT>/&<param name=\"NOADS\" value=\"$NOADS\">/"
linuxtrade.av $FLAGS "moz v2 v1" tmp.$i >>pf.log 2>&1 &
((++i))
done
|