If you didn't want to get the volume,and it always in the last.You can try this:
yourDict = { # assume it is a dict.Json is also OK.
"Time Series (Daily)": {
"2020-04-02": {
"1. open": "1693.5300",
"2. high": "1726.7600",
"3. low": "1664.1300",
"4. close": "1724.8600",
"5. volume": "766313"
},
"2020-04-01": {
"1. open": "1737.2800",
"2. high": "1762.4399",
"3. low": "1685.3700",
"4. close": "1685.4600",
"5. volume": "1243600"
}
}
}
temp = "^KS11 |{} |\n"
result = ""
temp = "^KS11 |{} |\n" # put data into {}
result = "" # use string
# Easy string handle
for i in yourDict["Time Series (Daily)"]:
# get the value in each dict
numberList = list(yourDict["Time Series (Daily)"][i].values())[:-1] # extract them
oneLineNumber = " |".join(numberList)# make them together
oneLineStr = temp.format(oneLineNumber) # Add them
result += oneLineStr
print(result)
The result(more one "\n"):
^KS11 |20200402|1693.5300 |1726.7600 |1664.1300 |1724.8600 |
^KS11 |20200401|1737.2800 |1762.4399 |1685.3700 |1685.4600 |
Or one line code:
yourDict = {
"Time Series (Daily)": {
"2020-04-02": {
"1. open": "1693.5300",
"2. high": "1726.7600",
"3. low": "1664.1300",
"4. close": "1724.8600",
"5. volume": "766313"
},
"2020-04-01": {
"1. open": "1737.2800",
"2. high": "1762.4399",
"3. low": "1685.3700",
"4. close": "1685.4600",
"5. volume": "1243600"
}
}
}
print("\n".join(["^KS11 |{} |".format(i.replace("-","")+"|"+" |".join(list(yourDict["Time Series (Daily)"][i].values())[:-1])) for i in yourDict["Time Series (Daily)"]]))
This is(no more "\n"):
^KS11 |20200402|1693.5300 |1726.7600 |1664.1300 |1724.8600 |
^KS11 |20200401|1737.2800 |1762.4399 |1685.3700 |1685.4600 |
(Maybe there is better way)
^KS11means?