This commit is contained in:
2025-03-16 22:29:23 +01:00
parent 13b68876aa
commit daed79d060
2 changed files with 5 additions and 5 deletions

View File

@ -220,14 +220,14 @@ def search_indice(indice):
price = soup.find("div", {"data-test": "instrument-price-last"}) price = soup.find("div", {"data-test": "instrument-price-last"})
price_change = soup.find("span", {"data-test": "instrument-price-change"}) price_change = soup.find("span", {"data-test": "instrument-price-change"})
price_change_percent = soup.find("span", {"data-test": "instrument-price-change-percent"}) price_change_percent = soup.find("span", {"data-test": "instrument-price-change-percent"})
porcentaje = price_change_percent.text.strip().replace("(", "").replace(")", "").replace("%", "")
if price and price_change and price_change_percent: if price and price_change and price_change_percent:
data = { data = {
"indice": indice, "indice": indice,
"valorActual": price.text.replace(",", "").strip(), # Convertir a número "valorActual": price.text.replace(",", "").strip(), # Convertir a número
"cambio": price_change.text.replace(",", "").strip(), # Convertir a número "cambio": price_change.text.replace(",", "").strip(), # Convertir a número
"porcentaje": price_change_percent.text.strip().replace("(", "").replace(")", "") # Eliminar paréntesis "porcentaje": porcentaje # Eliminar paréntesis
} }
logging.info(data) logging.info(data)
# Enviar los datos al bot de Telegram # Enviar los datos al bot de Telegram

View File

@ -16,9 +16,9 @@ public class TelegramController {
public void sendMessage(@RequestBody IndiceRequest request) { public void sendMessage(@RequestBody IndiceRequest request) {
String mensaje = String.format( String mensaje = String.format(
"*📊 Índice:* `%s`\n" + "*📊 Índice:* `%s`\n" +
"*💰 Valor Actual:* `%,.2f`\n" + "*💰 Valor Actual:* `%s`\n" + // Usamos %s para enviar el valor tal como se recibe
"*📉 Cambio:* `%,.2f`\n" + "*📉 Cambio:* `%s`\n" + // Lo mismo para el cambio
"*📈 Cambio(%):* `%s`", "*📈 Cambio(%):* `%s`", // Lo mismo para el porcentaje
request.getIndice(), request.getValorActual(), request.getPorcentaje() request.getIndice(), request.getValorActual(), request.getPorcentaje()
); );
telegramBot.sendMessage(telegramBot.CHAT_ID, mensaje ); telegramBot.sendMessage(telegramBot.CHAT_ID, mensaje );