Search code examples
datelivecode

How can I extract the API details for the current day only?


I have the following bit of code, which gives me all the information about IBM in dictionary format, but it includes the same information for many different dates far behind the current date. How would I extract the information for the CURRENT date only?

on mouseUp
   put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP") into field "myData"
end mouseUp

Solution

  • The trick here is to parse each small block of text by date. The "itemDelimiter" can be set to any string, and looking at the contents of the url call, I would use the string "{,".

    Now you can, for example:

     on mouseUp
       put url("https://www.alphavantage.co/query function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP") into field "myData"
    
       set the itemDel to "},"
       answer item 6 of fld "myData"
    end mouseUp
    

    You can collect each item as required and process away.