-3
am with the following Javascript function:
function main() {
let data = fazGet("https://economia.awesomeapi.com.br/json/all");
let moedaJSON = JSON.parse(data);
console.log(moedaJSON)
const keys = Object.keys(moedaJSON)
keys.forEach(key => {
document.getElementById("Nome1").innerHTML += moedaJSON[key]["name"] + "<br>";
document.getElementById("Alta1").innerHTML += moedaJSON[key]["high"] + "<br>";
document.getElementById("Baixa1").innerHTML += moedaJSON[key]["low"] + "<br>";
document.getElementById("Compra1").innerHTML += moedaJSON[key]["bid"] + "<br>";
document.getElementById("Venda1").innerHTML += moedaJSON[key]["ask"] + "<br>";
})
I want to do the same thing in Python, however, the variable "key" it has different names. It refers to an iten of an API dictionary that I will put right below.
moedas = {
"USD": {
"code": "USD",
"codein": "BRL",
"name": "Dólar Americano/Real Brasileiro",
"high": "5.6769",
"low": "5.6142",
"varBid": "0.0038",
"pctChange": "0.07",
"bid": "5.6191",
"ask": "5.6208",
"timestamp": "1618585377",
"create_date": "2021-04-16 12:02:59"
},
"DOGE": {
"code": "DOGE",
"codein": "BRL",
"name": "Dogecoin/Real Brasileiro",
"high": "2.36",
"low": "0.733879",
"varBid": "1.43577199",
"pctChange": "192.92",
"bid": "2.18",
"ask": "2.18",
"timestamp": "1618584926",
"create_date": "2021-04-16 11:55:27"
}}
NOTE: This dictionary above it is the same as this link, I only put a part of it as an example and not to be something big. Link here
In Json as you can see, we have "USD", "DOGE", etc... How do I make these names become variaves to facilitate the code. All this later I will put with Django so this need to change the script.
There is no way to convert the DOM HTML for python.
– Augusto Vasques
It doesn’t have to be the DOM, just the way to get the API value. I have a dictionary inside another dictionary, I want to call the values of the second dictionary without having to type the item of the first.
– Enryck
@Augustovasques is talking about DOM in the browser or is talking about DOM only?
– Guilherme Nascimento
@Guilhermenascimento, is the DOM HTML, as the link passed, because the MCVE of AP makes extensive use of this. So far I do not understand the question and much less the answer, both have no relation to the example presented.
– Augusto Vasques
From the link you sent "DOM was designed to be independent of any specific programming language" @Augustovasques, I’m having trouble understanding your first comment yet
– Guilherme Nascimento
@Guilhermenascimento, how would that line look
document.getElementById("Nome1").innerHTML += moedaJSON[key]["name"] + "<br>";
python?– Augusto Vasques
@Augustovasques this is not a matter of DOM, it is a specific feature of the DOM interface in Javascript, the problem is that the first comment meant something else.
– Guilherme Nascimento
@Guilhermenascimento, what is the question Script that is in Javascript for Python. I can not do because the DOM used by the function prevents me translation.
– Augusto Vasques
@Augustovasques I am not saying that the question is not confused, I just want to say that the first comment sounds something else, because it was not "gift" used (DOM is the "model"), but the "API DOM" that there is not something exactly the same, although it can be compensated in other ways, but now by your last comment it has come to understand that you refer to API of this and not to DOM in fact.
– Guilherme Nascimento
@Guilhermenascimento, correct. I understood what my failure was as to the terminology chosen and used. Thank you for the correction, I will strive to choose the terminology better and not be ambiguous when commenting.
– Augusto Vasques