Files
btgo-playwright/config.py
Marius Mutu d0e5c0c460 fix(login): citeste credentialele din .env, nu din env-ul mostenit
Scraper-ul e pornit ca subproces de telegram_trigger_bot.py cu
env=os.environ.copy(). Bot-ul isi incarca .env la pornire, deci copia
contine parola veche; load_dotenv() din config.py nu suprascrie o
variabila deja existenta, asa ca dupa schimbarea parolei scraper-ul
trimitea in continuare parola veche - BT respingea login-ul, push-ul 2FA
nu mai pleca si ramaneam blocati 300s in "Timeout 2FA".

- config.py: BTGO_USERNAME/BTGO_PASSWORD se citesc direct din .env
  (dotenv_values), restul variabilelor raman din environment ca sa nu
  strice TELEGRAM_MESSAGE_ID / SEND_AS_ZIP transmise de bot la fiecare run.
- btgo_scraper.py: detectie a mesajului de eroare de pe pagina de login in
  bucla de asteptare 2FA -> esec rapid cu motivul real, plus screenshot
  de diagnostic (si la respingere, si la timeout, cat browser-ul e viu).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YbuWZ699EFeYfPA3nNraa9
2026-08-19 11:30:38 +03:00

69 lines
2.6 KiB
Python

"""
Configurare pentru BTGO Scraper
Citeste configuratii din variabile de mediu (.env)
"""
from dotenv import load_dotenv, dotenv_values
import os
# Incarca variabilele de mediu din fisierul .env
load_dotenv()
# Credentialele se citesc DIRECT din .env, nu din environment.
# Motiv: scraper-ul e pornit ca subproces de telegram_trigger_bot.py, care ii da
# o copie a propriului environment. Bot-ul si-a incarcat .env-ul la pornire, deci
# environment-ul mostenit contine parola veche, iar load_dotenv() (fara override)
# nu suprascrie o variabila deja existenta -> se trimitea parola veche la BT si
# nu mai pleca push-ul 2FA. Nu folosim load_dotenv(override=True) pentru ca
# bot-ul transmite intentionat prin environment variabile de rulare
# (TELEGRAM_MESSAGE_ID, TELEGRAM_CHAT_ID, SEND_AS_ZIP, BALANCES_ONLY).
_ENV_FILE = dotenv_values()
class Config:
"""Clasa pentru gestionarea configuratiilor aplicatiei"""
# Credentials
BTGO_USERNAME = _ENV_FILE.get('BTGO_USERNAME') or os.getenv('BTGO_USERNAME')
BTGO_PASSWORD = _ENV_FILE.get('BTGO_PASSWORD') or os.getenv('BTGO_PASSWORD')
# Browser settings
HEADLESS = os.getenv('HEADLESS', 'false').lower() == 'true'
# Timeouts
TIMEOUT_2FA_SECONDS = int(os.getenv('TIMEOUT_2FA_SECONDS', 120))
# Paths
OUTPUT_DIR = os.getenv('OUTPUT_DIR', './data')
LOG_DIR = './logs'
# Features
SCREENSHOT_ON_ERROR = os.getenv('SCREENSHOT_ON_ERROR', 'true').lower() == 'true'
DOWNLOAD_TRANSACTIONS = os.getenv('DOWNLOAD_TRANSACTIONS', 'true').lower() == 'true'
LOG_LEVEL = os.getenv('LOG_LEVEL', 'INFO')
# Notification settings
ENABLE_NOTIFICATIONS = os.getenv('ENABLE_NOTIFICATIONS', 'false').lower() == 'true'
# Email settings (SMTP)
EMAIL_ENABLED = os.getenv('EMAIL_ENABLED', 'false').lower() == 'true'
SMTP_SERVER = os.getenv('SMTP_SERVER')
SMTP_PORT = int(os.getenv('SMTP_PORT', 587))
SMTP_USERNAME = os.getenv('SMTP_USERNAME')
SMTP_PASSWORD = os.getenv('SMTP_PASSWORD')
EMAIL_FROM = os.getenv('EMAIL_FROM')
EMAIL_TO = os.getenv('EMAIL_TO')
# Telegram settings
TELEGRAM_ENABLED = os.getenv('TELEGRAM_ENABLED', 'false').lower() == 'true'
TELEGRAM_BOT_TOKEN = os.getenv('TELEGRAM_BOT_TOKEN')
TELEGRAM_CHAT_ID = os.getenv('TELEGRAM_CHAT_ID')
@classmethod
def validate(cls):
"""Valideaza ca toate configuratiile obligatorii sunt setate"""
if not cls.BTGO_USERNAME or not cls.BTGO_PASSWORD:
raise ValueError("BTGO_USERNAME si BTGO_PASSWORD trebuie setate in .env")
if cls.TIMEOUT_2FA_SECONDS < 30:
raise ValueError("TIMEOUT_2FA_SECONDS trebuie sa fie minim 30 secunde")