Skip to content

A simple command-line habit tracker built in Python. It allows users to create and manage habits (daily/weekly), track check-offs, see due items, and calculate streaks. Data is stored in a SQLite database via SQLAlchemy ORM. Export functions (JSON/CSV) enable further analysis in Excel or BI tools.

Notifications You must be signed in to change notification settings

JulienLaucke/Object_Oriented_and_Functional_Programming_with_Python_DLBDSOOFPP01-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Habit Tracker (Python, SQLite, SQLAlchemy)

This project was developed as part of the IU module
Object-Oriented and Functional Programming with Python (DLBDSOOFPP01)

A small, robust habit tracker with clear domain logic, daily/weekly period handling, streak analytics, and a simple CLI.
Data is persisted in SQLite via SQLAlchemy 2.0.

Table of Contents


Features

  • Create and list habits (filter by periodicity)
  • Check-offs with normalized period bounds (day / ISO week)
  • View which habits are due today/this week
  • Longest streak analytics (per habit or best overall)
  • Export habits and checks to JSON and CSV

Setup

Clone or download this repository, then install dependencies:

python -m pip install -r requirements.txt

# Add and list
python -m habits.cli add "Drink water" --periodicity daily
python -m habits.cli list

# List only weekly habits
python -m habits.cli list-by --periodicity weekly

# Check now (marks as done for the current period)
python -m habits.cli check "Drink water"

# Show which habits are due
python -m habits.cli due

# Streaks
python -m habits.cli streak "Drink water"
python -m habits.cli streak-all

# Export data
python -m habits.cli export-habits --format json --path export/habits.json
python -m habits.cli export-checks --format csv  --path export/checks.csv
python -m habits.cli export-checks --format json --path export/checks_drink.json --name "Drink water"

Usage

All commands are run from the project root:

# Add and list
python -m habits.cli add "Drink water" --periodicity daily
python -m habits.cli list

# List only weekly habits
python -m habits.cli list-by --periodicity weekly

# Check now (marks as done for the current period)
python -m habits.cli check "Drink water"

# Show which habits are due
python -m habits.cli due

# Streaks
python -m habits.cli streak "Drink water"
python -m habits.cli streak-all

# Summary of all streaks
python -m habits.cli summary

# Manage habits
python -m habits.cli delete "Drink water"
python -m habits.cli rename "Drink water" "Hydration"

# Export data
python -m habits.cli export-habits --format json --path export/habits.json
python -m habits.cli export-checks --format csv  --path export/checks.csv
python -m habits.cli export-checks --format json --path export/checks_drink.json --name "Drink water"


All data is stored in habits.db (SQLite file in the project root).

Example Output

Habit creation and list

CLI Screenshot

The output shows:

  • Two new habits created (daily & weekly)
  • List of all habits with periodicity and timestamps

Check-off and due

CLI Screenshot

The output shows:

  • One habit checked off for the current period
  • Due command listing pending habits

Streak analytics

CLI Screenshot

The output shows:

  • Longest streak for a single habit
  • Best overall streak across all habits

Design Decisions

UTC-only timestamps → avoids timezone/DST issues

Period start as key (00:00 or Monday 00:00) → ensures idempotent checks (UNIQUE(habit_id, period_start))

Pure functions for analytics (longest streak) → easy to test

Separation of concerns:

db.py → engine & session

models.py → ORM tables

repo.py → repository with business logic

cli.py → command line interface

Tests

Run the unit tests with:

pytest -q

Sample tests are included in tests/test_core.py and cover:

Period normalization (start_of_day, start_of_iso_week)

Period bounds (daily, weekly)

Longest streak calculation

Roadmap

Delete or rename habits (Check)

Summary analytics (Check)

Optional GUI (Streamlit dashboard) (In Progress)

About

A simple command-line habit tracker built in Python. It allows users to create and manage habits (daily/weekly), track check-offs, see due items, and calculate streaks. Data is stored in a SQLite database via SQLAlchemy ORM. Export functions (JSON/CSV) enable further analysis in Excel or BI tools.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages