nueva configuracion problema objeto
This commit is contained in:
@ -205,15 +205,15 @@ def search_from_indices_file():
|
||||
logging.info(f"Error al leer el archivo 'indices.txt': {e}")
|
||||
|
||||
def search_indice(indice):
|
||||
base_url = f"https://www.investing.com/indices/{indice.url}"
|
||||
|
||||
base_url = f"https://www.investing.com/indices/{indice['url']}"
|
||||
|
||||
try:
|
||||
response = requests.get(base_url, headers=HEADERS)
|
||||
|
||||
if response.status_code != 200:
|
||||
logging.info(f"Error al acceder a la página para la consulta '{indice.nombre}': {response.status_code}")
|
||||
logging.info(f"Error al acceder a la página para la consulta '{indice['nombre']}': {response.status_code}")
|
||||
return
|
||||
|
||||
|
||||
soup = BeautifulSoup(response.content, 'html.parser')
|
||||
|
||||
# Buscar los valores dentro del HTML
|
||||
@ -225,21 +225,22 @@ def search_indice(indice):
|
||||
|
||||
if price and price_change and price_change_percent:
|
||||
data = {
|
||||
"indice": indice.nombre,
|
||||
"valorActual": price.text.replace(",", "").strip(), # Convertir a número
|
||||
"cambio": price_change.text.replace(",", "").strip(), # Convertir a número
|
||||
"porcentaje": porcentaje # Eliminar paréntesis
|
||||
"indice": indice["nombre"],
|
||||
"valorActual": price.text.replace(",", "").strip(),
|
||||
"cambio": price_change.text.replace(",", "").strip(),
|
||||
"porcentaje": porcentaje
|
||||
}
|
||||
logging.info(data)
|
||||
|
||||
# Enviar los datos al bot de Telegram
|
||||
response_telegram = requests.post(TELEGRAM_BOT_URL, json=data)
|
||||
|
||||
if response_telegram.status_code == 200:
|
||||
logging.info(f"Mensaje enviado a Telegram correctamente para '{indice.nombre}'")
|
||||
logging.info(f"Mensaje enviado a Telegram correctamente para '{indice['nombre']}'")
|
||||
else:
|
||||
logging.error(f"Error enviando mensaje a Telegram: {response_telegram.status_code} - {response_telegram.text}")
|
||||
else:
|
||||
logging.info(f"No se encontraron datos para el índice '{indice.nombre}'.")
|
||||
logging.info(f"No se encontraron datos para el índice '{indice['nombre']}'.")
|
||||
|
||||
except requests.RequestException as e:
|
||||
logging.error(f"Error en la solicitud: {e}")
|
||||
|
Reference in New Issue
Block a user