from pycoingecko import CoinGeckoAPI

cg = CoinGeckoAPI() #Ja retorna o Json serializado (Objeto)

#listaCryptos = cg.get_coins_markets(vs_currency='usd', price_change_percentage='1h,24h,7d')

msghtml = """<p style="font-family:verdana">
                    <p style="font-size:20px">
                        {}
                    </p>
                    <p style="color:green">
                        7D: {}%
                        <br />
                        24H: {}%
                    </p>
                </p>"""

"""for item in btc:
    print(item.id + ": em 1H: " + 
        item.price_change_percentage_1h_in_currency + ", em 24H: " + 
        item.price_change_percentage_24h_in_currency + ", em 7D: " +
        item.price_change_percentage_7d_in_currency)"""

def filtrarMaiorQue(lista, chave, maiorQue):
    listaRetorno = []

    for item in lista:
        for key, value in item.items():
            if (key == chave and int(value) > maiorQue):
                listaRetorno.append(item)
    
    return listaRetorno

def mostrar(lista):
    retorno = ""

    id = ""
    val7D = ""
    val24H = ""

    for item in lista:
        for key, value in item.items():
            if (key == "id"):
                id = value
            if (key == "price_change_percentage_7d_in_currency"):
                val7D = value
            if (key == "price_change_percentage_24h_in_currency"):
                val24H = value
            
        retorno += id + " -> em 7D: " + str(round(val7D, 2)) + "%, em 24H: " + str(round(val24H, 2)) + "%\n"
        #retorno += msghtml.format(id.upper(), str(round(val7D, 2)), str(round(val24H, 2)))
    
    return retorno

"""if __name__ == '__main__':
    lista = filtrar7D(listaCryptos)
    lista = filtrar24H(lista)
    #lista = filtrar1H(lista)
    mostrar(lista)"""
from pycoingecko import CoinGeckoAPI

cg = CoinGeckoAPI() #Ja retorna o Json serializado (Objeto)

#listaCryptos = cg.get_coins_markets(vs_currency='usd', price_change_percentage='1h,24h,7d')

msghtml = """<p style="font-family:verdana">
                    <p style="font-size:20px">
                        {}
                    </p>
                    <p style="color:green">
                        7D: {}%
                        <br />
                        24H: {}%
                    </p>
                </p>"""

"""for item in btc:
    print(item.id + ": em 1H: " + 
        item.price_change_percentage_1h_in_currency + ", em 24H: " + 
        item.price_change_percentage_24h_in_currency + ", em 7D: " +
        item.price_change_percentage_7d_in_currency)"""

def filtrarMaiorQue(lista, chave, maiorQue):
    listaRetorno = []

    for item in lista:
        for key, value in item.items():
            if (key == chave and int(value) > maiorQue):
                listaRetorno.append(item)
    
    return listaRetorno

def mostrar(lista):
    retorno = ""

    id = ""
    val7D = ""
    val24H = ""

    for item in lista:
        for key, value in item.items():
            if (key == "id"):
                id = value
            if (key == "price_change_percentage_7d_in_currency"):
                val7D = value
            if (key == "price_change_percentage_24h_in_currency"):
                val24H = value
            
        retorno += id + " -> em 7D: " + str(round(val7D, 2)) + "%, em 24H: " + str(round(val24H, 2)) + "%\n"
        #retorno += msghtml.format(id.upper(), str(round(val7D, 2)), str(round(val24H, 2)))
    
    return retorno

"""if __name__ == '__main__':
    lista = filtrar7D(listaCryptos)
    lista = filtrar24H(lista)
    #lista = filtrar1H(lista)
    mostrar(lista)"""
#Ja retorna o Json serializado (Objeto) #listaCryptos = cg.get_coins_markets(vs_currency='usd', price_change_percentage='1h,24h,7d') <p style="font-family:verdana">                     <p style="font-size:20px">                         {}                     </p>                     <p style="color:green">                         7D: {}%                         <br />                         24H: {}%                     </p>                 </p> for item in btc:     print(item.id + ": em 1H: " +          item.price_change_percentage_1h_in_currency + ", em 24H: " +          item.price_change_percentage_24h_in_currency + ", em 7D: " +         item.price_change_percentage_7d_in_currency) #retorno += msghtml.format(id.upper(), str(round(val7D, 2)), str(round(val24H, 2))) if __name__ == '__main__':     lista = filtrar7D(listaCryptos)     lista = filtrar24H(lista)     #lista = filtrar1H(lista)     mostrar(lista)