-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
128 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Update Indexes | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 */12 * * *' | ||
|
||
jobs: | ||
update-indicadores: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
check-latest: true | ||
cache: 'yarn' | ||
- name: Install dependencies | ||
run: yarn install --immutable --immutable-cache --check-cache | ||
- name: Update indicadores.json | ||
run: yarn update-indexes | ||
- name: Commit and push changes | ||
run: | | ||
git config --global user.name 'github-actions[bot]' | ||
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | ||
git add assets/indicadores.json | ||
git commit -m 'Update indicadores.json with latest values' | ||
git push | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const filePath = path.join(__dirname, 'assets', 'indicadores.json'); | ||
const indicadores = require(filePath); | ||
|
||
async function fetchPoupanca() { | ||
try { | ||
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); | ||
console.log('Poupanca value fetched:', value); | ||
return value; | ||
} catch (error) { | ||
console.error('Error fetching Poupanca:', error); | ||
} | ||
} | ||
|
||
async function fetchDi() { | ||
try { | ||
console.log('Fetching DI...'); | ||
const response = await axios.get('https://api.bcb.gov.br/dados/serie/bcdata.sgs.4391/dados/ultimos/13?formato=json'); | ||
const data = response.data.slice(1); // Ignores the partial value of current month | ||
const value = data.map(item => parseFloat(item.valor)).reduce((acc, value) => acc + value, 0); | ||
console.log('DI value fetched:', value); | ||
return value; | ||
} catch (error) { | ||
console.error('Error fetching DI:', error); | ||
} | ||
} | ||
|
||
async function fetchSelic() { | ||
try { | ||
console.log('Fetching Selic...'); | ||
const response = await axios.get('https://www.bcb.gov.br/api/servico/sitebcb/historicotaxasjuros'); | ||
const value = response.data.conteudo[0].MetaSelic; | ||
console.log('Selic value fetched:', value); | ||
return value; | ||
} catch (error) { | ||
console.error('Error fetching Selic:', error); | ||
} | ||
} | ||
|
||
async function updateIndicadores() { | ||
try { | ||
const poupancaValue = await fetchPoupanca(); | ||
const selicValue = await fetchSelic(); | ||
const cdiValue = await fetchDi(); | ||
|
||
indicadores.poupanca.value = poupancaValue; | ||
indicadores.selic.value = selicValue; | ||
indicadores.cdi.value = cdiValue; | ||
|
||
fs.writeFileSync(filePath, JSON.stringify(indicadores, null, 2)); | ||
console.log('indicadores.json updated successfully'); | ||
} catch (error) { | ||
console.error('Error updating indicadores.json:', error); | ||
} | ||
} | ||
|
||
updateIndicadores(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters