How to Run the Daily Stock Analysis Script: Complete Setup and Usage Guide
Execute python main.py from the repository root after installing dependencies with pip install -r requirements.txt and configuring the required API keys and stock list in a .env file.
The daily stock analysis system from the ZhuLinsen/daily_stock_analysis repository provides automated equity analysis through a command-line interface centered on main.py. This Python application orchestrates data fetching, AI-powered analysis via the StockAnalysisPipeline, and multi-channel notifications through a flexible execution architecture. Whether you need a one-time market scan or scheduled daily reports, the script supports multiple execution modes controlled via the parse_arguments function.
Prerequisites and Configuration
Before executing the script, you must install dependencies and configure environment variables that the src/config.py module loads at startup.
Install Python Dependencies
The system requires Python 3.10 or higher. Install the required packages using the provided requirements file:
pip install -r requirements.txt
The requirements.txt includes core dependencies such as pypinyin, openpyxl, imgkit, and litellm. For testing environments, use requirements-ci.txt which adds test-only packages.
Configure the Environment File
Copy the example environment file and populate mandatory variables:
cp .env.example .env
Edit .env to include at minimum:
STOCK_LIST: Comma-separated stock codes (e.g.,600519,300750,AAPL)- One LLM API key:
GEMINI_API_KEY,OPENAI_API_KEY, orAIHUBMIX_KEY - One notification channel:
WECHAT_WEBHOOK_URL,FEISHU_WEBHOOK_URL, orEMAIL_SENDERpaired withEMAIL_PASSWORD
The src/config.py module validates these variables during the bootstrap phase described in main.py lines 13-16.
Basic One-Shot Execution
The simplest invocation runs the full analysis pipeline immediately. According to the implementation in main.py, the parse_arguments function (lines 24-38) processes CLI flags before initializing the StockAnalysisPipeline in src/core/pipeline.py.
Run Full Analysis
Execute the complete workflow including per-stock analysis and market review:
python main.py
This loads the configuration, initializes logging via src/logging_config.py, fetches data for all stocks in STOCK_LIST, runs AI analysis, and sends notifications through the configured channels.
Common Execution Flags
Tailor the execution using these parameters defined in the argument parser:
--dry-run: Pull market data only, skipping AI analysis and notifications--stocks 600519,000001: OverrideSTOCK_LISTto analyze only specific codes--no-notify: Execute analysis without sending push notifications--debug: Enable verbose debug logging via the logging configuration module
Example with multiple flags:
python main.py --dry-run --stocks hk00700,600519 --debug
Advanced Execution Modes
The script supports specialized modes for specific workflow requirements, each handled by dedicated modules under src/core/.
Market Review Only
Skip individual stock analysis and run only the market review pipeline implemented in src/core/market_review.py:
python main.py --market-review
This mode generates aggregated market commentary without processing individual equity positions.
Scheduled Daily Runs
Enable the built-in scheduler to automate execution. The scheduler block in main.py (lines 92-99) handles the timing logic:
python main.py --schedule
By default, this runs immediately, then schedules daily execution at 18:00. To start the scheduler without an immediate run:
python main.py --schedule --no-run-immediately
The scheduler re-reads STOCK_LIST before each execution, allowing dynamic modification of the watchlist without restarting the process. Control concurrency using the --workers flag (e.g., --workers 5 for five concurrent threads).
Web UI and API Server
Launch the FastAPI interface and optional React frontend:
python main.py --serve # Start server and run analysis once
python main.py --serve-only # Start server without running analysis
The src/webui_frontend.py module prepares static assets before the server binds to 0.0.0.0:8000. Combine with scheduling to run the API and background analyzer simultaneously:
python main.py --serve --schedule --no-run-immediately
Docker Deployment
For production environments, the repository provides containerized services defined in docker/docker-compose.yml. The configuration defines two distinct services:
server: Runs the FastAPI web interface using--serve-onlyanalyzer: Runs the scheduler using--schedule
Quick Start with Docker Compose
docker-compose -f ./docker/docker-compose.yml up -d
This builds the multi-stage image defined in docker/Dockerfile and starts both services. Mount volumes for .env, data, logs, and reports to persist configuration and output between container restarts.
Run services individually:
docker-compose -f ./docker/docker-compose.yml up -d server # API only
docker-compose -f ./docker/docker-compose.yml up -d analyzer # Scheduler only
Summary
- Entry point: All execution paths flow through
main.py, which delegates tosrc/core/pipeline.pyfor analysis logic. - Configuration: Mandatory variables reside in
.env, loaded bysrc/config.pyat startup. - Execution modes: Choose from one-shot analysis (
python main.py), scheduled runs (--schedule), or API server mode (--serve). - Docker: Use
docker/docker-compose.ymlto deploy persistentserverandanalyzerservices. - Customization: Override stock lists with
--stocks, suppress notifications with--no-notify, or test connectivity with--dry-run.
Frequently Asked Questions
What Python version is required to run the daily stock analysis script?
The system requires Python 3.10 or higher. This ensures compatibility with the type hints and async features used in src/core/pipeline.py and the FastAPI web interface.
How do I run the script without sending notifications to my configured channels?
Add the --no-notify flag to any execution command. This runs the full analysis pipeline including AI generation but skips the final notification dispatch step, allowing you to review results in the logs or output files only.
Can I analyze specific stocks instead of the entire list defined in .env?
Yes. Use the --stocks flag followed by comma-separated codes to override the STOCK_LIST environment variable for that execution. For example: python main.py --stocks 600519,300750 analyzes only those two securities regardless of your .env configuration.
How do I run the script continuously as a daily automated service?
Use the --schedule flag combined with --no-run-immediately to start the background scheduler without executing an immediate analysis. The scheduler, implemented in main.py lines 92-99, triggers runs daily at 18:00 UTC. For containerized deployments, use the analyzer service in docker/docker-compose.yml which wraps this scheduling mode.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →