From 84ad98b4d3ceb5b1a4cc780b298812cfc204090f Mon Sep 17 00:00:00 2001 From: "Arthur K." Date: Sun, 8 Mar 2026 10:23:44 +0300 Subject: [PATCH] feat: min balance --- .env.example | 3 +++ Dockerfile | 1 + src/server.py | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 00d9430..36b0dfd 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,9 @@ TARGET_SIZE=5 # Poll interval for checking new accounts when pool incomplete (seconds) POLL_INTERVAL=30 +# Minimum balance threshold - switch token when balance <= MIN_BALANCE +MIN_BALANCE=0 + # HTTPS proxy URL (used by Firefox and balance API) HTTPS_PROXY=http://user:pass@host:port diff --git a/Dockerfile b/Dockerfile index ba2d493..9930828 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,6 +49,7 @@ ENV PYTHONUNBUFFERED=1 ENV PORT=80 ENV TARGET_SIZE=5 ENV POLL_INTERVAL=30 +ENV MIN_BALANCE=0 ENV DATA_DIR=/data ENV EXTRAS_DIR=/extras ENV EMAILS_FILE=/data/emails.txt diff --git a/src/server.py b/src/server.py index 4dd2d0e..7c253e5 100644 --- a/src/server.py +++ b/src/server.py @@ -11,6 +11,7 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) PORT = int(os.environ.get("PORT", 8080)) +MIN_BALANCE = float(os.environ.get("MIN_BALANCE", "0")) async def on_startup(app: web.Application): @@ -51,7 +52,7 @@ async def token_handler(request: web.Request) -> web.Response: continue balance = balance_data.get("balance", balance_data.get("remaining", 0)) - if balance is None or balance <= 0: + if balance is None or balance <= MIN_BALANCE: await pop_token() await trigger_refill() continue