[dev] Jonah patches
John Morrissey
jwm@horde.net
Fri Nov 29 22:37:00 2002
Attached are two patches to Jonah:
jonah-stocksite.patch adds the company's web site URL and Market Center, if
available, to the stock quote display.
jonah-datafixup.patch fixes up some places in the stock feed that didn't
format currency to two decimal places (1.2 instead of 1.20). It also fixes
the display of company names that contain XML entities (for example, "S&P
500" would display as "P 500" because entities are broken up and fed
separately to the parser). Lastly, it takes a stab at applying correct
casing to company names. If a company name is in all caps, it will ucwords()
it. Makes "CORNING INC." display as "Corning Inc.", which looks a bit nicer.
This doesn't make NasdaqQuotes:: perfect, but it fixes the bigger things
I've noticed.
john
--
John Morrissey _o /\ ---- __o
jwm@horde.net _-< \_ / \ ---- < \,
www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__
-------------- next part --------------
Index: lib/NasdaqQuotes.php
===================================================================
RCS file: /repository/jonah/lib/NasdaqQuotes.php,v
retrieving revision 1.1
diff -u -u -r1.1 NasdaqQuotes.php
--- lib/NasdaqQuotes.php 19 Aug 2002 21:52:51 -0000 1.1
+++ lib/NasdaqQuotes.php 29 Nov 2002 22:11:00 -0000
@@ -141,6 +141,10 @@
// mop up
xml_parser_free($this->parser);
+
+ if (preg_match('/^[A-Z\\s]+$/', $this->quote['name'])) {
+ $this->quote['name'] = ucwords(strtolower($this->quote['name']));
+ }
}
/**
@@ -209,7 +213,11 @@
switch ($this->currentTag) {
case $nameKey:
case $indexKey:
- $this->quote['name'] = $data;
+ if (array_key_exists('name', $this->quote)) {
+ $this->quote['name'] .= $data;
+ } else {
+ $this->quote['name'] = $data;
+ }
break;
case $marketStatusIndexKey:
case $marketStatusKey:
@@ -230,14 +238,14 @@
$this->quote['low'] = $data;
break;
case $yearHighKey:
- $this->quote['yearlyHigh'] = $data;
+ $this->quote['yearlyHigh'] = sprintf('%.2f', $data);
break;
case $yearLowKey:
- $this->quote['yearlyLow'] = $data;
+ $this->quote['yearlyLow'] = sprintf('%.2f', $data);
break;
case $lastValueKey:
case $lastPriceKey:
- $this->quote['lastPrice'] = $data;
+ $this->quote['lastPrice'] = sprintf('%.2f', $data);
break;
case $changeValueKey:
case $changePriceKey:
@@ -252,7 +260,7 @@
break;
case $lastCloseIndexKey:
case $lastCloseKey:
- $this->quote['lastClose'] = $data;
+ $this->quote['lastClose'] = sprintf('%.2f', $data);
break;
case $bestBidKey:
$this->quote['bestBid'] = $data;
-------------- next part --------------
Index: stockquote.php
===================================================================
RCS file: /repository/jonah/stockquote.php,v
retrieving revision 1.3
diff -u -u -r1.3 stockquote.php
--- stockquote.php 16 Oct 2002 04:42:28 -0000 1.3
+++ stockquote.php 29 Nov 2002 22:20:58 -0000
@@ -48,7 +48,19 @@
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%">';
if (array_key_exists('name', $quotes->quote)) {
echo '<tr><td class="text" valign="top">';
- echo 'Name:</td><td>' . htmlentities($quotes->quote['name']) . '</td></tr>';
+ echo 'Name:</td><td>';
+ if (array_key_exists('website', $quotes->quote)) {
+ echo '<a href="' . $quotes->quote['website'] . '">';
+ }
+ echo htmlentities($quotes->quote['name']);
+ if (array_key_exists('website', $quotes->quote)) {
+ echo '</a>';
+ }
+ echo '</td></tr>';
+ }
+ if (array_key_exists('marketCenter', $quotes->quote)) {
+ echo '<tr><td class="text" valign="top">';
+ echo 'Market Center:</td><td>' . htmlentities($quotes->quote['marketCenter']) . '</td></tr>';
}
if (array_key_exists('lastPrice', $quotes->quote)) {
echo '<tr><td class="text" valign="top">';
More information about the dev
mailing list