Skip to content

Commit

Permalink
Improving indicators update script
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelorodrigo committed Jan 17, 2025
1 parent e7675bf commit 7b5ab6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion update-indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ async function fetchPoupanca() {
console.log('Fetching Poupanca...');
const response = await axios.get('https://api.bcb.gov.br/dados/serie/bcdata.sgs.195/dados/ultimos/1?formato=json');
const value = parseFloat(response.data[0].valor);
if(isNaN(value)) {
console.error('Invalid Poupanca value received:', value);
console.error('Full payload:', response.data);
return null;
}
console.log('Poupanca value fetched:', value);
return value;
} catch (error) {
Expand Down Expand Up @@ -48,7 +53,11 @@ async function updateIndicadores() {
const selicValue = await fetchSelic();
const cdiValue = await fetchDi();

indicadores.poupanca.value = poupancaValue;
if (!poupancaValue || isNaN(poupancaValue)) {
console.warn('Skipping update: Invalid poupanca value.');
indicadores.poupanca.value = poupancaValue;
}

indicadores.selic.value = selicValue;
indicadores.cdi.value = cdiValue;

Expand Down

4 comments on commit 7b5ab6d

@navossoc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apesar do ajuste, aparentemente a poupança está quebrada até hoje...

[]`s

@marcelorodrigo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@navossoc valeu por avisar 😄
Acredito que agora tá tudo joia, dá uma conferida se o calculo vem correto pra você?

@navossoc
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parece que sim, qualquer coisa eu volto para encher o saco ;)

[]`s

@marcelorodrigo
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR's são sempre bem vindos.
Obrigado!

Please sign in to comment.