testsAndMisc-archive/python_pkg/lichess_bot/run.sh
Krzysztof kuhy Rudnicki 22333931cc refactor: rename folders to fix N999, INP001, S311 linting rules
- Rename PYTHON/ to python_pkg/ (fix N999 uppercase folder)
- Rename camelCase folders to snake_case:
  - randomJPG -> random_jpg
  - tagDivider -> tag_divider
  - downloadCats -> download_cats
  - keyboardCoop -> keyboard_coop
  - extractLinks -> extract_links
  - scapeWebsite -> scrape_website
- Rename camelCase files:
  - generateJpeg.py -> generate_jpeg.py
  - tagDivider.py -> tag_divider.py
- Rename poker-modifier-app to poker_modifier_app (fix INP001)
- Add __init__.py to poker_modifier_app
- Replace random module with secrets.SystemRandom (fix S311)
- Fix S110 try-except-pass with contextlib.suppress
- Update all imports and config references
2025-11-30 21:20:17 +01:00

71 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Resolve script directory and repo root
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd -- "$SCRIPT_DIR/../.." && pwd)"
# Load a local .env if present
if [[ -f "$SCRIPT_DIR/.env" ]]; then
set -a
# shellcheck disable=SC1090
source "$SCRIPT_DIR/.env"
set +a
fi
# Helper to persist the token to .env
save_token() {
local env_file="$SCRIPT_DIR/.env"
# Keep other lines, remove existing LICHESS_TOKEN, then append new one
if [[ -f "$env_file" ]]; then
grep -v '^LICHESS_TOKEN=' "$env_file" > "$env_file.tmp" || true
printf 'LICHESS_TOKEN=%s\n' "$LICHESS_TOKEN" >> "$env_file.tmp"
mv "$env_file.tmp" "$env_file"
else
printf 'LICHESS_TOKEN=%s\n' "$LICHESS_TOKEN" > "$env_file"
fi
chmod 600 "$env_file" 2>/dev/null || true
echo "Saved token to $env_file"
}
# Optional: --token <TOKEN> to set for this run
if [[ "${1:-}" == "--token" || "${1:-}" == "-t" ]]; then
if [[ "${2:-}" == "" ]]; then
echo "--token requires a value"
exit 2
fi
export LICHESS_TOKEN="$2"
shift 2
fi
# Ask for token if not set and export it for this run
if [[ -z "${LICHESS_TOKEN:-}" ]]; then
printf "Paste your Lichess API token and press Enter: "
read -r token
export LICHESS_TOKEN="$token"
if [[ -z "$LICHESS_TOKEN" ]]; then
echo "No token provided. Aborting."
exit 1
fi
echo "Token received."
save_token
else
# If token came from CLI or env, still persist so next run won't prompt
save_token
fi
# Choose python: prefer local venv
PY="$SCRIPT_DIR/.venv/bin/python"
if [[ ! -x "$PY" ]]; then
PY="python"
fi
cd "$REPO_ROOT"
echo "Using Python: $PY"
echo "Repository root: $REPO_ROOT"
echo "Starting Lichess bot..."
echo "Tip: Open another terminal to watch logs; press Ctrl+C here to stop."
trap 'echo; echo "Stopping bot (Ctrl+C)."' INT
"$PY" -m PYTHON.lichess_bot.main "$@"