-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
43 lines (33 loc) · 1.36 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import streamlit as st
import requests
if 'selic' not in st.session_state:
st.session_state['selic'] = 1.0
st.session_state['cdi'] = 0.9
def atualizar():
url = "https://www.bcb.gov.br/api/servico/sitebcb/historicotaxasjuros"
headers = {
"Host": "www.bcb.gov.br",
"Accept": "application/json, text/plain, */*",
"Cache-Control": "no-cache",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
"Content-Type": "application/json;charset=UTF-8"
}
response = requests.get(url, headers=headers)
if response.status_code != 200:
st.warning("Erro ao tentar atualizar a SELIC automaticamente")
st.stop()
data = response.json()
selic = data['conteudo'][0]['MetaSelic']
st.session_state['selic'] = selic
st.session_state['cdi'] = selic - 0.1
st.title("Configuração")
c1, c2, _ = st.columns([2, 2, 6])
with c1:
st.metric("SELIC", st.session_state['selic'])
with c2:
st.metric("CDI", st.session_state['cdi'])
btn = st.button('Atualizar a SELIC automaticamente', icon=":material/refresh:",
type="primary", on_click=atualizar)
if btn:
st.success("SELIC atualizada com sucesso!")
st.markdown("***Fonte:** [Banco Central](https://www.bcb.gov.br/controleinflacao/historicotaxasjuros)")