Skip to Content.
Sympa Menu

internetworkers - Re: stock quotes on a web site

internetworkers AT lists.ibiblio.org

Subject: Internetworkers: http://www.ibiblio.org/internetworkers/

List archive

Chronological Thread  
  • From: "tengu typed, not" <tengu AT unc.edu>
  • To: InterNetWorkers <internetworkers AT franklin.oit.unc.edu>
  • Subject: Re: stock quotes on a web site
  • Date: Tue, 15 Aug 2000 16:25:18 -0400 (EDT)


On Tue, 15 Aug 2000, L D Beavers wrote:
This sound simple but is turning out to be harder than it sounds. We are
building a web site and want to include five or six stock quotes and industry
news. Any good (i.e. cheap) suggestions for portal sources ?

There's nothing cheaper than rolling your own.
Hack example follows- a fancier way would be to use Perl's GD object.
Much, much simpler would be to just use text.
Never let me hear 'portal' on this list again.

#!/usr/local/bin/perl
use Math::Fraction;
$poidog = `/usr/local/bin/wget --quiet -O -
http://www.nasdaq.com/nasdaq/nasdaq_mss.asp?symbol=POI`;
@fields = qw (
symbol
name
date
time
last_sale
best_ask
dunno
previous_close
todays_high
todays_low
best_bid
time_2
net_change
volume
dunno_2
);
@values = split(/\|/,$poidog);
@slice{@fields} = @values;
$sale = "$slice{last_sale}"; #"1234567890.125";
$change = "$slice{net_change}";
if ($change eq "unch"){
$change = '0';
}
$real_length_text = length($sale);
$real_length_change = length($change);
$sale_fraction = frac($sale, MIXED);
$change_fraction = frac($change, MIXED);
if ("0" ne (substr ($change, 0, 1))) {
if ("-" eq (substr ($change, 0, 1))) {
$change_fraction = "-"."$change_fraction";
}elsif ("+" eq (substr ($change, 0, 1))) {
$change_fraction = "+"."$change_fraction";
}
}

PARSE_NUMBER($sale_fraction,'>/export/local/ns-home/docs/poidog-docs/assets/ticker.txt');
PARSE_NUMBER($change_fraction,'>/export/local/ns-home/docs/poidog-docs/assets/change.txt');



#####################
#
# make the html
#
#####################

sub PARSE_NUMBER {
my ($text,$file) = @_;
open TICKER, "$file" || die "Can't open $file";
$text =~ /(?:(.*)\s)*(.*)\/(.*)/;
($d1,$d2,$d3) = ($1,$2,$3);
print "Whole Number: $1\nNumerator: $2\nDenominator: $3\n$file\n";
if ($file =~ /ticker/) {
print "Matched TICKER\n";
IMAJ($d1,"images/numbers/whole");
print TICKER "<IMG
SRC=\"/images/numbers/numerator/spacer.gif\" HSPACE=\"0\" VSPACE=\"0\"
BORDER=\"0\">\n" if
($d1);
} elsif ($file =~ /change/) {
print "Matched CHANGE\n";
IMAJ($d1,"images/numbers/change");
print TICKER "<IMG
SRC=\"/images/numbers/change/spacer.gif\" HSPACE=\"0\" VSPACE=\"0\"
BORDER=\"0\">\n" if
($d1);
}
IMAJ($d2,"images/numbers/numerator");
print TICKER "<IMG
SRC=\"/images/numbers/numerator/slash.gif\" HSPACE=\"0\" VSPACE=\"0\"
BORDER=\"0\">\n" if
($d2);
IMAJ($d3,"images/numbers/denominator") if ($d3);
close TICKER;
}


sub IMAJ {
my ($name,$place) = @_;
foreach ($i = 0; $i < (length($name)); $i++) {
$number = substr ($name, $i, 1);
print TICKER "<IMG
SRC=\"$place/$number.gif\" HSPACE=\"0\" VSPACE=\"0\" BORDER=\"0\">\n";

}
}
close TICKER;
}
---
Never underestimate the bandwidth of a station wagon full of tapes.
-- Dr. Warren Jackson, Director, UTCS




  • stock quotes on a web site, L D Beavers, 08/15/2000
    • <Possible follow-up(s)>
    • Re: stock quotes on a web site, tengu typed, not, 08/15/2000

Archive powered by MHonArc 2.6.24.

Top of Page