Files
telegram_bots/main.py
T
2025-11-04 01:03:19 +01:00

45 lines
1.1 KiB
Python

import os
from pathlib import Path
from telegram_utils import send_message
ENV_FILE = Path(".env")
MESSAGE_TO_SEND = "Holaa prueba 1"
def load_env_file(path: Path) -> None:
if not path.exists():
raise FileNotFoundError(
f"No se encontró el archivo de entorno: {path}"
)
with path.open(encoding="utf-8") as env_file:
for raw_line in env_file:
line = raw_line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
key, value = line.split("=", 1)
key = key.strip()
value = value.strip().strip('"').strip("'")
if key and key not in os.environ:
os.environ[key] = value
def main() -> None:
load_env_file(ENV_FILE)
api_key = os.environ.get("TELEGRAM_API_KEY")
chat_id = os.environ.get("TELEGRAM_CHAT_ID")
if not api_key or not chat_id:
raise RuntimeError(
"Asegúrate de definir TELEGRAM_API_KEY y TELEGRAM_CHAT_ID en tu .env."
)
send_message(api_key, chat_id, MESSAGE_TO_SEND)
if __name__ == "__main__":
main()