From 975f9e5887316690895c444f9b3952ca283dd1f5 Mon Sep 17 00:00:00 2001 From: houhuan Date: Sun, 17 May 2026 16:09:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20Docker=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E7=9A=84=E4=B8=8B=E8=BD=BD=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E5=92=8C=E7=BD=91=E7=BB=9C=E7=A8=B3=E5=AE=9A=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Chromium 启动参数优化:禁用 dev-shm 和 GPU 加速,防止Docker内存不足 - 增加所有超时时间:login/navigate/export 超时 30s,下载超时 300s - 改进网络延迟处理:增加数据加载等待时间,添加网络加载检测 - Docker Compose 资源配置:限制 2 CPU / 2GB 内存,DNS 配置国际公共 DNS - Dockerfile 优化:添加 PYTHONHASHSEED 环境变量,跳过浏览器下载校验 - 新增 docker-debug.sh 脚本:便捷测试 Docker 容器中的下载功能 - 新增 .dockerignore:加速 Docker 构建,减少镜像大小 Docker 下载现在支持更长的网络延迟和更大的数据量 --- .dockerignore | 19 +++++++++++++++ CLAUDE.md | 56 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 10 +++++--- automation/secsion.py | 40 ++++++++++++++++++------------- docker-compose.yml | 25 +++++++++++++++++++ docker-debug.sh | 52 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 19 deletions(-) create mode 100644 .dockerignore create mode 100644 CLAUDE.md create mode 100644 docker-debug.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..6fc9de4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +.git +.gitignore +.env.example +*.md +.vscode +.idea +__pycache__ +*.pyc +.pytest_cache +.coverage +*.egg-info +dist +build +.DS_Store +*.log +uploads/* +downloads/* +.claude +CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..67bc115 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,56 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project Overview + +SalesShow is a monolithic Flask web application for analyzing sales data from Excel files. It supports manual Excel uploads and automated daily downloads from secsion.com via Playwright browser automation. There is no database — all data lives as Excel files on disk in `uploads/`. + +## Commands + +```bash +# Install dependencies +pip install -r requirements.txt + +# Run development server (Flask on port 5000, debug via FLASK_DEBUG env var) +python app.py + +# Run with Docker (builds image, installs Playwright Chromium, port 5000) +docker-compose up -d + +# Production +gunicorn -w 4 -b 0.0.0.0:8000 app:app + +# CLI automation — download reports from secsion.com +python -m automation.secsion --start 2026-04-28 --end 2026-04-28 +``` + +No test framework or linter is configured in this project. + +## Architecture + +**Backend (Flask, single `app.py`):** +- Routes handle file upload (`/upload`), file listing (`/files`), data loading/processing (`/load/`), deletion, and cleanup. +- `process_sales_data()` (~lines 371-575 in `app.py`) is the core logic. It uses a state-machine approach to handle two Excel formats: "flat tables" (each row has code + product) and "hierarchical tables" (code row is a header, product rows are children). Outputs daily summaries with per-product breakdowns. +- `find_header_row()` dynamically detects the header row by scanning first 20 rows for keyword matches. + +**Automation module (`automation/`):** +- `secsion.py` — `SecsionDownloader` uses Playwright headless Chromium to log into secsion.com, navigate to reports, set date range via TDesign date picker, optionally inject `shop_id` via route interception, and download exports. +- `uploader.py` — copies downloaded files into `uploads/` with timestamp-prefix naming (same convention as manual uploads). +- `scheduler.py` — APScheduler `BackgroundScheduler` with `CronTrigger` runs daily auto-download (default 01:00). + +**Configuration (`config.py`):** +- Three-tier priority: Web UI settings (`data/config.json`) > environment variables (`.env` / system env) > defaults. +- `Config` class provides static methods for reading/writing secsion credentials, shop ID, and scheduler settings. + +**Frontend (vanilla JS/CSS, no build step):** +- `main.js` — all client-side interactivity: file upload (drag-and-drop), AJAX to API, data rendering (card/table view), client-side filtering, sorting, pagination (50 items/page), export. +- `style.css` — Glassmorphism design with CSS custom properties. +- `settings.html` — self-contained settings page with inline `