snipe/app/wizard/setup.py
pyr0ball eb05be0612
Some checks are pending
CI / API — lint + test (pull_request) Waiting to run
CI / Web — typecheck + test + build (pull_request) Waiting to run
feat: wire Forgejo Actions CI/CD workflows (#22)
- ci.yml: API lint (ruff F+I) + pytest, web vue-tsc + vitest + build
- mirror.yml: push to GitHub (CircuitForgeLLC) + Codeberg (CircuitForge) on main/tags
- release.yml: Docker build → Forgejo registry + release via API; GHCR deferred pending BSL policy (cf-agents#3)
- .cliff.toml: git-cliff changelog config for semver releases
- pyproject.toml: add [dev] extras (pytest, ruff), ruff config
- Fix 45 ruff violations across codebase (import sorting, unused vars, unused imports)
2026-04-06 00:00:28 -07:00

54 lines
2 KiB
Python

"""First-run wizard: collect eBay credentials and write .env."""
from __future__ import annotations
from pathlib import Path
import streamlit as st
from circuitforge_core.wizard import BaseWizard
class SnipeSetupWizard(BaseWizard):
"""
Guides the user through first-run setup:
1. Enter eBay Client ID (EBAY_CLIENT_ID) + Secret (EBAY_CLIENT_SECRET)
2. Choose sandbox vs production
3. Verify connection (token fetch)
4. Write .env file
"""
def __init__(self, env_path: Path = Path(".env")):
self._env_path = env_path
def run(self) -> bool:
"""Run the setup wizard. Returns True if setup completed successfully."""
st.title("🎯 Snipe — First Run Setup")
st.info(
"To use Snipe, you need eBay developer credentials. "
"Register at developer.ebay.com and create an app to get your Client ID (EBAY_CLIENT_ID) and Secret (EBAY_CLIENT_SECRET)."
)
client_id = st.text_input("eBay Client ID (EBAY_CLIENT_ID)", type="password")
client_secret = st.text_input("eBay Client Secret (EBAY_CLIENT_SECRET)", type="password")
env = st.selectbox("eBay Environment", ["production", "sandbox"])
if st.button("Save and verify"):
if not client_id or not client_secret:
st.error("Both Client ID and Secret are required.")
return False
# Write .env
self._env_path.write_text(
f"EBAY_CLIENT_ID={client_id}\n"
f"EBAY_CLIENT_SECRET={client_secret}\n"
f"EBAY_ENV={env}\n"
f"SNIPE_DB=data/snipe.db\n"
)
st.success(f".env written to {self._env_path}. Reload the app to begin searching.")
return True
return False
def is_configured(self) -> bool:
"""Return True if .env exists and has eBay credentials."""
if not self._env_path.exists():
return False
text = self._env_path.read_text()
return "EBAY_CLIENT_ID=" in text and "EBAY_CLIENT_SECRET=" in text