Skip to content

Commit 0a4bc2d

Browse files
suan babyclaude
andcommitted
fix: address additional code review issues
1. Add safe float conversion for change_pct to prevent TypeError - Handles string values from data providers - Converts to float with fallback to None 2. Update CHANGELOG.md with PR changes - Add financial data and dividend metrics to email reports - Add sector/board information with change percentage - Support HK and US market sector data - Fix board lookup when ranking API transiently fails - Remove incorrect dividend ratio field mapping - Fix Chinese character garble in logs - Archive completed OpenSpec changes Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 9f6f74e commit 0a4bc2d

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1111

1212
<!-- 新条目格式:- [类型] 描述(类型取值:新功能/改进/修复/文档/测试/chore)-->
1313
<!-- 每条独立一行追加到本段末尾,无需分类标题,合并时冲突最小 -->
14+
- [新功能] 邮件报告新增财务数据和分红送转指标展示
15+
- [新功能] 邮件报告新增关联板块涨跌幅信息展示
16+
- [新功能] 邮件报告支持港股和美股的板块数据展示
17+
- [改进] 板块查询在排名 API 临时失败时仍尝试获取,提升数据可用性
18+
- [修复] 移除错误的分红比例字段映射,避免收益率计算放大 10 倍
19+
- [修复] 修复日志中中文乱码问题
20+
- [文档] 归档已完成的 OpenSpec 变更
1421
- [新功能] 通知网关新增 ntfy 一等渠道,支持通过 `NTFY_URL` / `NTFY_TOKEN` 推送并接入 Web 测试、路由、Actions 与诊断。
1522
- [新功能] 通知网关新增 Gotify 一等渠道,支持通过 `GOTIFY_URL` / `GOTIFY_TOKEN` 推送 Markdown 文本并接入 Web 测试、路由、Actions 与诊断。
1623
- [修复] 收紧 ntfy 结构化校验,避免 URL 编码空白 topic 被误判为有效通知端点。

src/notification.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,12 @@ def generate_dashboard_report(
10611061
for board in belong_boards[:5]:
10621062
if isinstance(board, dict):
10631063
name = board.get('name', '')
1064-
change_pct = board.get('change_pct')
1064+
change_pct_raw = board.get('change_pct')
1065+
# 安全转换 change_pct 为浮点数
1066+
try:
1067+
change_pct = float(change_pct_raw) if change_pct_raw is not None else None
1068+
except (ValueError, TypeError):
1069+
change_pct = None
10651070
if name:
10661071
# 涨跌幅格式化
10671072
if change_pct is not None:
@@ -1431,7 +1436,11 @@ def generate_wechat_dashboard(self, results: List[AnalysisResult]) -> str:
14311436
for board in belong_boards[:5]:
14321437
if isinstance(board, dict):
14331438
name = board.get('name', '')
1434-
change_pct = board.get('change_pct')
1439+
change_pct_raw = board.get('change_pct')
1440+
try:
1441+
change_pct = float(change_pct_raw) if change_pct_raw is not None else None
1442+
except (ValueError, TypeError):
1443+
change_pct = None
14351444
if name:
14361445
if change_pct is not None:
14371446
change_str = f"{change_pct:+.2f}%"
@@ -1726,7 +1735,11 @@ def generate_single_stock_report(self, result: AnalysisResult) -> str:
17261735
for board in belong_boards[:5]:
17271736
if isinstance(board, dict):
17281737
name = board.get('name', '')
1729-
change_pct = board.get('change_pct')
1738+
change_pct_raw = board.get('change_pct')
1739+
try:
1740+
change_pct = float(change_pct_raw) if change_pct_raw is not None else None
1741+
except (ValueError, TypeError):
1742+
change_pct = None
17301743
price = board.get('price')
17311744
if name:
17321745
if change_pct is not None:

0 commit comments

Comments
 (0)