Last active
November 2, 2022 21:02
-
-
Save Fabiocke/1f108362b5426cde5439bcc60bf48645 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import requests | |
| from base64 import b64encode | |
| # Função para buscar o trading name | |
| def get_trading_name(ticker): | |
| # cria os parâmetros | |
| params = {"language":"pt-br","pageNumber":1,"pageSize":20,"company":ticker} | |
| #params = '{"language":"pt-br","pageNumber":1,"pageSize":20,"company":"' + ticker + '"}' | |
| # para codificar em base64 é preciso fazer a conversão dos parâmetros em bytes | |
| params = bytes(str(params), encoding="ascii") | |
| # faz a codificação em formato bytes | |
| string = b64encode(params) | |
| # decodifica para transformar bytes em string | |
| string = string.decode() | |
| # faz a requisição com os parâmetros | |
| r = requests.get(r'https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetInitialCompanies/'+ | |
| string) | |
| # retorna o trading name da empresa, (é necessário remover pontos e barras) | |
| for i in r.json()['results']: | |
| if i['issuingCompany'].lower() == ticker.lower(): | |
| return i['tradingName'].replace('/','').replace('.','') | |
| # Se a empresa não for encontrada, retorna a mensagem de erro | |
| raise ValueError('Empresa não encontrada') | |
| # Função para obter os proventos | |
| def proventos(ticker): | |
| # encontra o trading name da empresa | |
| tradingName = get_trading_name(ticker) | |
| # cria os parâmetros com o trading name | |
| params = {"language":"pt-br","pageNumber":1,"pageSize":99999,"tradingName":tradingName} | |
| # codifica os parâmetros em base64 | |
| params = bytes(str(params), encoding="ascii") | |
| string = b64encode(params) | |
| string = string.decode() | |
| r = requests.get('https://sistemaswebb3-listados.b3.com.br/listedCompaniesProxy/CompanyCall/GetListedCashDividends/'+ | |
| string) | |
| return r.json() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment