refactor: rename stockbuddy and remove venv
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
.env
|
.env
|
||||||
|
venv/
|
||||||
|
|||||||
4
SKILL.md
4
SKILL.md
@@ -1,9 +1,9 @@
|
|||||||
---
|
---
|
||||||
name: stock-buddy
|
name: stockbuddy
|
||||||
description: 港股分析助手,提供港股技术面和基本面综合分析,给出买入/卖出操作建议。支持单只股票查询分析、持仓批量分析和持仓管理。当用户提到"港股"、"股票分析"、"持仓分析"、"买入建议"、"卖出建议"、港股代码(如 0700.HK、700)或港股公司名称(如腾讯、阿里、比亚迪)时触发此技能。
|
description: 港股分析助手,提供港股技术面和基本面综合分析,给出买入/卖出操作建议。支持单只股票查询分析、持仓批量分析和持仓管理。当用户提到"港股"、"股票分析"、"持仓分析"、"买入建议"、"卖出建议"、港股代码(如 0700.HK、700)或港股公司名称(如腾讯、阿里、比亚迪)时触发此技能。
|
||||||
---
|
---
|
||||||
|
|
||||||
# 港股分析助手 (Stock Buddy)
|
# 港股分析助手 (StockBuddy)
|
||||||
|
|
||||||
## 概述
|
## 概述
|
||||||
|
|
||||||
|
|||||||
@@ -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 分钟
|
CACHE_TTL_SECONDS = 600 # 缓存有效期 10 分钟
|
||||||
|
LEGACY_CACHE_DIR = Path.home() / ".stock_buddy_cache"
|
||||||
MAX_RETRIES = 3
|
MAX_RETRIES = 3
|
||||||
RETRY_BASE_DELAY = 2
|
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:
|
def _read_cache(code: str, period: str) -> dict | None:
|
||||||
"""读取缓存"""
|
"""读取缓存"""
|
||||||
cache_file = CACHE_DIR / _cache_key(code, period)
|
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():
|
if not cache_file.exists():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(cache_file, "r", encoding="utf-8") as f:
|
with open(cache_file, "r", encoding="utf-8") as f:
|
||||||
cached = json.load(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):
|
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_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
cache_file = CACHE_DIR / _cache_key(code, period)
|
cache_file = CACHE_DIR / _cache_key(code, period)
|
||||||
try:
|
try:
|
||||||
@@ -710,8 +727,12 @@ def main():
|
|||||||
|
|
||||||
if args.clear_cache:
|
if args.clear_cache:
|
||||||
import shutil
|
import shutil
|
||||||
if CACHE_DIR.exists():
|
cleared = False
|
||||||
shutil.rmtree(CACHE_DIR)
|
for path in (CACHE_DIR, LEGACY_CACHE_DIR):
|
||||||
|
if path.exists():
|
||||||
|
shutil.rmtree(path)
|
||||||
|
cleared = True
|
||||||
|
if cleared:
|
||||||
print("✅ 缓存已清除")
|
print("✅ 缓存已清除")
|
||||||
else:
|
else:
|
||||||
print("ℹ️ 无缓存可清除")
|
print("ℹ️ 无缓存可清除")
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
python3 portfolio_manager.py update <代码> [--price <价格>] [--shares <数量>] [--note <备注>]
|
python3 portfolio_manager.py update <代码> [--price <价格>] [--shares <数量>] [--note <备注>]
|
||||||
python3 portfolio_manager.py analyze [--output <输出文件>]
|
python3 portfolio_manager.py analyze [--output <输出文件>]
|
||||||
|
|
||||||
持仓文件默认保存在: ~/.hk_stock_portfolio.json
|
持仓文件默认保存在: ~/.stockbuddy/portfolio.json
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -20,11 +20,17 @@ import time
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
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:
|
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():
|
if not PORTFOLIO_PATH.exists():
|
||||||
return {"positions": [], "updated_at": None}
|
return {"positions": [], "updated_at": None}
|
||||||
with open(PORTFOLIO_PATH, "r", encoding="utf-8") as f:
|
with open(PORTFOLIO_PATH, "r", encoding="utf-8") as f:
|
||||||
@@ -34,6 +40,7 @@ def load_portfolio() -> dict:
|
|||||||
def save_portfolio(data: dict):
|
def save_portfolio(data: dict):
|
||||||
"""保存持仓数据"""
|
"""保存持仓数据"""
|
||||||
data["updated_at"] = datetime.now().isoformat()
|
data["updated_at"] = datetime.now().isoformat()
|
||||||
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
||||||
with open(PORTFOLIO_PATH, "w", encoding="utf-8") as f:
|
with open(PORTFOLIO_PATH, "w", encoding="utf-8") as f:
|
||||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
python3
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/usr/bin/python3
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
python3
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
lib
|
|
||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user