Compare the following stock arrays returned by http://download.finance.yahoo.com/d/quotes.csv?s=CAJ&f=snl1c1ohgvd1t1 :

Array
(
    [0] => "CAJ"
    [1] => "Canon
    [2] =>  Inc. Ameri"
    [3] => 42.39
    [4] => +0.74
    [5] => 42.14
    [6] => 42.49
    [7] => 42.01
    [8] => 239238
    [9] => "6/16/2010"
    [10] => "4:03pm"
    [11] => 385009
)
Array
(
    [0] => "TM"
    [1] => "Toyota Motor Corp"
    [2] => 72.78
    [3] => -0.26
    [4] => 72.95
    [5] => 73.00
    [6] => 72.41
    [7] => 306944
    [8] => "6/16/2010"
    [9] => "4:05pm"
    [10] => 1043350
)

Once this has been process by stockapi_fetch() we are returned with the following arrays:

Array
(
    [0] => CAJ
    [1] => Canon, Inc. Ameri
    [3] => 42.39
    [4] => +0.74
    [5] => 42.14
    [6] => 42.49
    [7] => 42.01
    [8] => 239238
    [9] => 6/16/2010
    [10] => 4:03pm
    [11] => 385009
)
Array
(
    [0] => TM
    [1] => Toyota Motor Corp
    [2] => 72.78
    [3] => -0.26
    [4] => 72.95
    [5] => 73.00
    [6] => 72.41
    [7] => 306944
    [8] => 6/16/2010
    [9] => 4:05pm
    [10] => 1043350
)

As one can see, the values with a key > 1 in the first array (which originally contained a comma in the name subsequently split by explode()) are offset by 1. This creates some problems. One of them being that stockapi_insert() relies on the key. So, if you save the above using directly with stockapi_save, you will have some incorrect entries in your DB.

I see two potential solutions. Either we rename the keys using the fields used to query yahoo (this may break modules using this API) OR as the patch provides here, we keep the keys consistent (and hopefully don't break anything)!

CommentFileSizeAuthor
stockapi.module.consistent_array_keys.patch1.08 KBfp

Comments

izmeez’s picture

This patch appears to work. Inserting CAJ in the Stock symbols shows the results correctly in the table of results with the name field complete with comma and the other fields as expected.

joseph.olstad’s picture

Status: Needs review » Closed (outdated)

Design change required , new data source
Please upgrade to 7.x-2.x
Thanks