如何仅提取当天的API详细信息?

时间:2018-12-10 23:40:12

标签: date livecode

我有下面的代码,它以字典格式为我提供了有关IBM的所有信息,但是对于许多不同的日期,它都包含相同的信息,而这些信息远远落后于当前日期。我将如何仅提取当前日期的信息?

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

2 个答案:

答案 0 :(得分:0)

这里的技巧是按日期解析每个小文本块。可以将“ itemDelimiter”设置为任何字符串,然后查看url调用的内容,我将使用字符串“ {,”。

现在您可以,例如:

 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

您可以根据需要收集每个项目并进行处理。

答案 1 :(得分:0)

您从服务中获取JSON,因此我认为最好的解决方案是将JSON转换为数组。您可以使用ImportJSON或JSON来做到这一点,

put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP") into tData
put JSONToArray(tData) into tArr   
# Get current date as ISO-date!
put the date into tDate
convert tDate to dateItems
put item 1 to 3 of tDate into tDate
replace "," with "-" in tDate
# Now get the current item in the array
put tArr["Time Series (Daily)"][tDate] into tToday
# To view in a normal field you can use combine 
combine tToday with return and tab
put tToday into field "myData"

从长远来看,我真的认为,如果在继续操作之前将JSON转换为更易于管理的内容,则运行起来会容易得多。