text: from authentication import Authentication
  from time import time
  from pymongo import MongoClient
  import os
  from dotenv import load_dotenv
  import hashlib
  from datetime import datetime
  
  
  class Balances:
      currencies_ids = {"0": "EUR", "1": "ARS", "2": "USD"}
  
      def __init__(self) -> None:
          load_dotenv()
          auth = Authentication()
          self.session = auth.session
          self.headers = auth.header
  
          mongo = MongoClient("localhost", 27017)
          hash_dni = hashlib.md5(os.getenv("DNI").encode()).hexdigest()
          self.db = mongo[hash_dni]
  
          self.base_url = "https://online.bbva.com.ar/fnetcore/servicios/cliente"
  
      def profileData(self):
          url = f"{self.base_url}/datosperfil?ts={int(time())}"
          resp = self.session.get(url, headers=self.headers)
  
      def getAccounts(self) -> dict:
          url = f"{self.base_url}/productos/cuentas?ts={int(time())}"
          resp = self.session.get(url, headers=self.headers).result()
          return resp.json()["result"]
  
      def getCards(self):
          url = f"{self.base_url}/productos/tarjetas?ts={int(time())}"
          resp = self.session.get(url, headers=self.headers)
          return resp
  
      def saveBalances(self):
          balances = []
          accounts_details = self.getAccounts()
          accounts = (
              accounts_details["cajasAhorro"] + accounts_details["cuentasCorriente"]
          )
          totals = {}
          for account in accounts:
              currency = self.currencies_ids[account["idMoneda"]]
              details = {
                  "id": account["id"],
                  "account_number": account["numero"],
                  "balance": float(account["saldo"]),
                  "currency": currency,
                  "type": account["tipoProducto"],
              }
              if currency not in totals:
                  totals[currency] = 0
              totals[currency] += details["balance"]
              balances.append(details)
  
          inserted = self.db.balances.insert_one(
              {"date": datetime.now(), "balances": balances, "totals": totals}
          )
  
  
  bal = Balances()
  bal.saveBalances()
  