def test_getCompany(self): db = Database() db.insertCompany( Company(cnpj="93.612.749/0001-70", name="Companhia Teste 1", rate=25, term=72, warranty="Terreno")) db.insertCompany( Company(cnpj="27.456.797/0001-92", name="Companhia Teste 2", rate=25, term=48, warranty="Imóvel")) db.insertCompany( Company(cnpj="26.805.322/0001-00", name="Companhia Teste 3", rate=35, term=36, warranty="Imóvel")) company = db.getCompany(cnpj="93.612.749/0001-70") db.database.company.delete_one({'cnpj': "93.612.749/0001-70"}) db.database.company.delete_one({'cnpj': "27.456.797/0001-92"}) db.database.company.delete_one({'cnpj': "26.805.322/0001-00"}) self.assertEqual(company.name, "Companhia Teste 1") self.assertEqual(company.rate, 25) self.assertEqual(company.term, 72) self.assertEqual(company.warranty, "Terreno")
async def getTop10Companies(): try: conn = await connectionFactory.getDBDriverConnection() resultSet = list(await conn.fetch(''' select e.nome as nome, e.simbolo_empresa as simbolo, e.regiao as regiao, e.setor as setor, e.rank as rank, c.preco as preco, c.volume as volume, c.data as dt_u_a, c.variacao as var, c.variacao_por_cento as vp from empresas e left join cotacoes c on e.simbolo_empresa = c.simbolo_empresa ORDER BY e.rank; ''')) companyList: list = [] for item in resultSet: dic = dict(item) company: Company = Company() company.setName(dic["nome"]) company.setRank(dic["rank"]) company.setRegion(dic["regiao"]) company.setSector(dic["setor"]) company.setSymbol(dic["simbolo"]) stock: CompanyStock = CompanyStock() stock.setChange(dic["var"]) stock.setChangePercent(dic["vp"]) stock.setPrice(dic["preco"]) stock.setLastUpdate(dic["dt_u_a"]) stock.setVolume(dic["volume"]) stock.setCompanySymbol(company.getSymbol()) company.setStock(stock) companyList.append(company) await conn.close() return companyList except Exception as exceptMsg: print("Falha ao obter lista de empresas top 10.", str(exceptMsg))
def test_cnpj_error(self): with self.assertRaises(ValueError): Company(cnpj="11.111.111/1111-11", name="Companhia Teste", rate=25, term=72, warranty="Terreno")
def test_set_atributtes(self): company = Company(cnpj="42.109.758/0001-02", name="Companhia Teste", rate=25, term=72, warranty="Terreno") self.assertEqual(company.cnpj, "42.109.758/0001-02") self.assertEqual(company.name, "Companhia Teste") self.assertEqual(company.rate, 25) self.assertEqual(company.term, 72) self.assertEqual(company.warranty, "Terreno")
def test_insertCompany(self): db = Database() db.insertCompany( Company(cnpj="42.109.758/0001-02", name="Companhia Teste 1", rate=25, term=72, warranty="Terreno")) db.insertCompany( Company(cnpj="42.742.578/0001-63", name="Companhia Teste 2", rate=25, term=48, warranty="Imóvel")) db.insertCompany( Company(cnpj="45.441.634/0001-18", name="Companhia Teste 3", rate=35, term=36, warranty="Imóvel")) db.database.company.delete_one({'cnpj': "42.109.758/0001-02"}) db.database.company.delete_one({'cnpj': "42.742.578/0001-63"}) db.database.company.delete_one({'cnpj': "45.441.634/0001-18"})
async def init_data(): ''' Função init_data - Responsável por inicializar os dados das 10 maiores empresas do Brasil na Bolsa de Valores no banco de dados. - A função espera que a função asincrona init_db seja executada para garantir que as tabelas e estrutura da base de dados sejá estabelecida antes de inserir os dados das empresas. - Essa função também é utilizada para atualizar novos dados das empresas que constem na API da Alpha Vantage. ''' await init_db() companies = { 'Petrobras': 'PETR4.SAO', 'Itaú Unibanco Holding': 'ITUB4.SAO', 'Banco Bradesco': 'BBDC4.SAO', 'Banco do Brasil': 'BBAS3.SAO', 'JBS': 'JBSS3.SAO', 'Vale': 'VALE3.SAO', 'Eletrobrás': 'ELET6.SAO', 'Itaúsa': 'ITSA4.SAO', 'Banco BTG Pactual': 'BPAC11.SAO', 'B3 - Bolsa de Valores': 'IBOV.SAO' } for company in companies: company_dao = CompanyDAO(db_session) price_dao = PriceDAO(db_session) company_data = company_dao.get_company_by_name(company) if company_data == None: new_company = Company(company, companies[company]) company_dao.register_company(new_company) for company_info in await get_request_daily( companies[company], 30): new_company_price = Price(new_company.company_id, float(company_info[1]['1. open']), float(company_info[1]['2. high']), float(company_info[1]['3. low']), float(company_info[1]['4. close']), company_info[0]) price_dao.register_company_price(new_company_price) print(f'Registering company {companies[company]}') await asyncio.sleep(12) else: continue
# coding: utf-8 import os from modules.database import Database from modules.models.financier import Financier from modules.models.company import Company saida = os.system("pip install -r requirements.pip") db = Database() db.client.drop_database('credit') db.insertFinancier(Financier(cnpj = "42.109.758/0001-02", name = "Banco do Pernambuco", rate = 25, term = 72, warranty = "Terreno")) db.insertFinancier(Financier(cnpj = "42.742.578/0001-63", name = "Banco Camargo de Araújo", rate = 10, term = 48, warranty = "Imóvel")) db.insertFinancier(Financier(cnpj = "27.948.482/0001-62", name = "InovaCred", rate = 12, term = 36, warranty = "Terreno")) db.insertFinancier(Financier(cnpj = "23.918.334/0001-44", name = "Banco do Pará", rate = 25, term = 72, warranty = "Terreno")) db.insertFinancier(Financier(cnpj = "81.396.636/0001-04", name = "Dinheiro Certo", rate = 10, term = 48, warranty = "Imóvel")) db.insertFinancier(Financier(cnpj = "38.265.772/0001-28", name = "CredFácil", rate = 12, term = 36, warranty = "Terreno")) db.insertCompany(Company(cnpj = "18.259.473/0001-73", name = "Empreendimentos do Sol", rate = 25, term = 72, warranty = "Terreno")) db.insertCompany(Company(cnpj = "14.886.257/0001-05", name = "Floricultura do Azevedo", rate = 25, term = 48, warranty = "Imóvel")) db.insertCompany(Company(cnpj = "63.816.653/0001-63", name = "Bar's Rock", rate = 12, term = 36 , warranty = "Terreno"))
def getCompany(self, cnpj = ""): result = self.database.company.find_one({'cnpj' : cnpj}) if result != None: return Company(cnpj = result['cnpj'], name = result['name'], rate = result['rate'], term = result['term'], warranty = result['warranty']) else: raise ValueError("Não há empresa cadastrada sob esse CNPJ no sistema")