如何仅提取当天的 API 详细信息?
How can I extract the API details for the current day only?
我有以下代码,它以字典格式为我提供了有关 IBM 的所有信息,但它包含了远远晚于当前日期的许多不同日期的相同信息。我将如何仅提取当前日期的信息?
on mouseUp
put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP") into field "myData"
end mouseUp
这里的技巧是按日期解析每个小文本块。 "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
您可以根据需要收集每个项目并处理。
您从服务中获得 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 转换为更易于管理的内容,我真的认为您 运行 会容易得多。
我有以下代码,它以字典格式为我提供了有关 IBM 的所有信息,但它包含了远远晚于当前日期的许多不同日期的相同信息。我将如何仅提取当前日期的信息?
on mouseUp
put url("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YPMBUVQ8AJXX1HQP") into field "myData"
end mouseUp
这里的技巧是按日期解析每个小文本块。 "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
您可以根据需要收集每个项目并处理。
您从服务中获得 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 转换为更易于管理的内容,我真的认为您 运行 会容易得多。