Olá a todos, a resolução do exercício proposto pelo professor. Gostaria de sugestões para melhorar o código.
import re, requests
url = "bytebank.com/cambio?quantidade=100&moedaOrigem=real&moedaDestino=dolar"
class ExtratorURL:
    def __init__(self, url):
        self.url = self.limpa_url(url)
        self.valida_url()
    def __len__(self):
        return len(self.url)
    def __str__(self):
        return f"{self.url} \nParâmetros: {self.get_url_parametros()}\nBase: {self.get_url_base()}"
    def __eq__(self, other):
        return self.url == other.url
    def limpa_url(self, url):
        if type(url) == str:
            return url.strip()
        else:
            return ""
    def valida_url(self):
        if not self.url:
            raise ValueError("A URL é uma string vazia")
        padrao_url = re.compile("(http(s)?://)?(www.)?bytebank.com(.br)?/cambio")
        match = padrao_url.match(self.url)
        if not match:
            raise ValueError("A URL não é válida.")
    def get_url_base(self):
        indice_interroga = self.url.find("?")
        url_base = self.url[:indice_interroga]
        return url_base
    def get_url_parametros(self):
        indice_interroga = self.url.find("?")
        url_parametros = self.url[indice_interroga + 1:]
        return url_parametros
    def get_valor_parametro(self, nome):
        indice_parametro = self.get_url_parametros().find(nome)
        indice_valor = indice_parametro + len(nome) + 1
        indice_e = self.get_url_parametros().find("&", indice_valor)
        if indice_e == -1:
            valor = self.get_url_parametros()[indice_valor:]
        else:
            valor = self.get_url_parametros()[indice_valor:indice_e]
        return valor
    def get_valores(self):
        origem = self.get_valor_parametro("moedaOrigem")
        destino = self.get_valor_parametro("moedaDestino")
        quantidade = self.get_valor_parametro("quantidade")
        return origem, destino, quantidade
class ConverteDolarReal:
    def __init__(self, origem, destino, valor):
        self.origem = origem
        self.destino = destino
        self.valor = int(valor)
    def __str__(self):
        return f"{self.origem} - {self.valor}\n{self.destino} - {self.converte_valor()}"
    @staticmethod
    def get_dolar():
        r = requests.get("https://economia.awesomeapi.com.br/last/USD-BRL")
        return float(r.json()["USDBRL"]["ask"])
    def converte_valor(self):
        if self.origem == "dolar":
            valor_convertido = self.valor * self.get_dolar()
            return round(valor_convertido, 2)
        else:
            valor_convertido = self.valor / self.get_dolar()
            return round(valor_convertido, 2) 
            