habit-tracker/README.md

1.2 KiB

习惯打卡记录器 (Habit Tracker)

一个基于 Flask 和 SQLite 的习惯打卡记录器后端 API。

技术栈

  • Python
  • Flask (Web 框架)
  • SQLite (数据库)
  • Peewee (ORM)

项目设置

  1. 安装依赖:
python -m venv venv
source venv/bin/activate  # On Windows use: venv\Scripts\activate
pip install -r requirements.txt
  1. 初始化数据库:
python init_db.py
  1. 运行服务器:
python app.py

API 文档

Base URL: /api/v1

1. 事项管理

创建事项

  • POST /habits
{
    "name": "晨跑",
    "description": "每天早上7点跑步",
    "periodicity": "daily",
    "reminder_time": "07:00",
    "icon": "🏃‍♂️",
    "color": "#FFAA00"
}

获取所有事项

  • GET /habits

修改事项

  • PUT /habits/{habit_id}

删除事项

  • DELETE /habits/{habit_id}

2. 打卡管理

打卡

  • POST /habits/{habit_id}/checkins
{
    "date": "2025-04-15",
    "note": "状态不错!"
}

获取打卡记录

  • GET /habits/{habit_id}/checkins?from=2025-04-01&to=2025-04-30

3. 数据统计

获取统计信息

  • GET /habits/{habit_id}/stats