refactor: rename stockbuddy and remove venv

This commit is contained in:
root
2026-03-30 22:50:18 +08:00
parent 50f674e431
commit dbdaca6f11
9 changed files with 36 additions and 16 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
__pycache__/
*.pyc
.env
venv/

View File

@@ -1,9 +1,9 @@
---
name: stock-buddy
name: stockbuddy
description: 港股分析助手,提供港股技术面和基本面综合分析,给出买入/卖出操作建议。支持单只股票查询分析、持仓批量分析和持仓管理。当用户提到"港股"、"股票分析"、"持仓分析"、"买入建议"、"卖出建议"、港股代码(如 0700.HK、700或港股公司名称如腾讯、阿里、比亚迪时触发此技能。
---
# 港股分析助手 (Stock Buddy)
# 港股分析助手 (StockBuddy)
## 概述

View File

@@ -38,8 +38,10 @@ except ImportError:
# 缓存与重试机制
# ─────────────────────────────────────────────
CACHE_DIR = Path.home() / ".stock_buddy_cache"
DATA_DIR = Path.home() / ".stockbuddy"
CACHE_DIR = DATA_DIR / "cache"
CACHE_TTL_SECONDS = 600 # 缓存有效期 10 分钟
LEGACY_CACHE_DIR = Path.home() / ".stock_buddy_cache"
MAX_RETRIES = 3
RETRY_BASE_DELAY = 2
@@ -53,8 +55,22 @@ def _cache_key(code: str, period: str) -> str:
def _read_cache(code: str, period: str) -> dict | None:
"""读取缓存"""
cache_file = CACHE_DIR / _cache_key(code, period)
if not cache_file.exists():
legacy_cache_file = LEGACY_CACHE_DIR / _cache_key(code, period)
if legacy_cache_file.exists():
try:
DATA_DIR.mkdir(parents=True, exist_ok=True)
CACHE_DIR.mkdir(parents=True, exist_ok=True)
cache_file.write_text(
legacy_cache_file.read_text(encoding="utf-8"),
encoding="utf-8",
)
except OSError:
cache_file = legacy_cache_file
if not cache_file.exists():
return None
try:
with open(cache_file, "r", encoding="utf-8") as f:
cached = json.load(f)
@@ -69,6 +85,7 @@ def _read_cache(code: str, period: str) -> dict | None:
def _write_cache(code: str, period: str, data: dict):
"""写入缓存"""
DATA_DIR.mkdir(parents=True, exist_ok=True)
CACHE_DIR.mkdir(parents=True, exist_ok=True)
cache_file = CACHE_DIR / _cache_key(code, period)
try:
@@ -710,8 +727,12 @@ def main():
if args.clear_cache:
import shutil
if CACHE_DIR.exists():
shutil.rmtree(CACHE_DIR)
cleared = False
for path in (CACHE_DIR, LEGACY_CACHE_DIR):
if path.exists():
shutil.rmtree(path)
cleared = True
if cleared:
print("✅ 缓存已清除")
else:
print(" 无缓存可清除")

View File

@@ -9,7 +9,7 @@
python3 portfolio_manager.py update <代码> [--price <价格>] [--shares <数量>] [--note <备注>]
python3 portfolio_manager.py analyze [--output <输出文件>]
持仓文件默认保存在: ~/.hk_stock_portfolio.json
持仓文件默认保存在: ~/.stockbuddy/portfolio.json
"""
import sys
@@ -20,11 +20,17 @@ import time
from datetime import datetime
from pathlib import Path
PORTFOLIO_PATH = Path.home() / ".hk_stock_portfolio.json"
DATA_DIR = Path.home() / ".stockbuddy"
PORTFOLIO_PATH = DATA_DIR / "portfolio.json"
LEGACY_PORTFOLIO_PATH = Path.home() / ".hk_stock_portfolio.json"
def load_portfolio() -> dict:
"""加载持仓数据"""
if not PORTFOLIO_PATH.exists() and LEGACY_PORTFOLIO_PATH.exists():
DATA_DIR.mkdir(parents=True, exist_ok=True)
PORTFOLIO_PATH.write_text(LEGACY_PORTFOLIO_PATH.read_text(encoding="utf-8"), encoding="utf-8")
if not PORTFOLIO_PATH.exists():
return {"positions": [], "updated_at": None}
with open(PORTFOLIO_PATH, "r", encoding="utf-8") as f:
@@ -34,6 +40,7 @@ def load_portfolio() -> dict:
def save_portfolio(data: dict):
"""保存持仓数据"""
data["updated_at"] = datetime.now().isoformat()
DATA_DIR.mkdir(parents=True, exist_ok=True)
with open(PORTFOLIO_PATH, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2)

View File

@@ -1 +0,0 @@
python3

View File

@@ -1 +0,0 @@
/usr/bin/python3

View File

@@ -1 +0,0 @@
python3

View File

@@ -1 +0,0 @@
lib

View File

@@ -1,5 +0,0 @@
home = /usr/bin
include-system-site-packages = false
version = 3.12.3
executable = /usr/bin/python3.12
command = /usr/bin/python3 -m venv /home/openclaw/.openclaw/workspace/stock-buddy/venv