Skip to content

BosTheCoder/leetcode-accountability

Repository files navigation

LeetCode Accountability

A Python package for tracking LeetCode problem-solving activity across multiple users and holding them accountable.

Screenshots

Weekly Run Terminal Output Splitwise Multiple Expenses Splitwise Expense Details
Terminal Weekly Run Splitwise Multiple Expenses Splitwise Expense Details

Features

  • Query the LeetCode GraphQL API to fetch user submissions
  • Track problems solved by difficulty level (Easy, Medium, Hard)
  • View statistics for multiple users over a specified time period
  • Command-line interface for quick access to statistics
  • Integration with Splitwise for financial accountability
  • Configurable user settings via JSON configuration

Installation

  1. Clone this repository
  2. Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install the required dependencies from requirements.txt:
pip install -r requirements.txt
  1. Set up your environment variables (see Configuration section)

Local Development Setup

Setting up the CLI alias

For convenient access to the LeetCode stats, you can add a shell function to your ~/.bashrc_additions file:

# ------------------------def stats()-----------------------------------------------------
# stats: get LeetCode statistics for the current week (Monday 5am to next Monday 5am)
# This function automatically calculates the date range for the current week
# and runs the LeetCode accountability CLI with those dates.
# Usage: stats [username] - if no username provided, shows stats for all active users
stats() {
  local project_dir="/path/to/your/leetcode-accountability"
  local username="$1"
  
  # Check if project directory exists
  [[ -d $project_dir ]] || { echo "⚠️  Project directory not found: $project_dir"; return 1; }
  
  # Calculate start date (last Monday 5am) and end date (next Monday 5am)
  local start_date=$(date -d "last monday + 5 hours" +"%Y-%m-%dT%H:%M:%S")
  local end_date=$(date -d "next monday + 5 hours" +"%Y-%m-%dT%H:%M:%S")
  
  # Navigate to project directory, activate venv, and run the CLI
  if [[ -n $username ]]; then
    # Run with specific username
    (cd "$project_dir" && \
     source .venv/bin/activate && \
     python -m leetcode_accountability.cli stats "$username" \
       --start-date "$start_date" \
       --end-date "$end_date")
  else
    # Run without username (shows all active users)
    (cd "$project_dir" && \
     source .venv/bin/activate && \
     python -m leetcode_accountability.cli stats \
       --start-date "$start_date" \
       --end-date "$end_date")
  fi
}
# -----------------------------------------------------------------------------

Replace /path/to/your/leetcode-accountability with the actual path to your cloned repository.

After adding this function:

  1. Run source ~/.bashrc to reload your shell configuration
  2. Use stats to get stats for all active users for the current week
  3. Use stats username to get stats for a specific user for the current week

Usage

Command-line Interface

The package provides two main commands:

Stats Command

View LeetCode submission statistics for specified users:

# Get stats for multiple users over the last 7 days (default)
python -m leetcode_accountability.cli stats user1 user2 user3

# Specify a custom number of days
python -m leetcode_accountability.cli stats user1 user2 --days 30

Weekly Run Command

Run the weekly accountability check for all active users. This will charge users for missed questions via Splitwise and print their stats:

# Run weekly accountability check with default settings (7 days, $10 per missed question)
python -m leetcode_accountability.cli weekly_run

# Customize the lookback period and cost per question
python -m leetcode_accountability.cli weekly_run --days 14 --cost-per-question 15.0

Architecture & Dependency Diagrams ( auto-generated )

Class Diagram Module Diagram
Class Diagram Module Diagram

The repository ships with UML diagrams that show package‐level dependencies and class relationships. They are generated with pyreverse (bundled inside pylint) and Graphviz and live in docs/classes/.

How to regenerate the images

# 1 – One-time tooling install
pipx install pylint            # gives you `pyreverse`
# Linux
sudo apt-get install graphviz
# macOS
# brew install graphviz

# 2 – Create fresh .dot files for the whole project
pyreverse -o dot -p myproject .

# 3 – Convert the .dot files to roomy PNGs and park them in docs/classes
dot -Tpng -Gsize=20,20\! -Granksep=2.0 -Gnodesep=1.0 packages_myproject.dot -o docs/classes/packages.png
dot -Tpng -Gsize=20,20\! -Granksep=2.0 -Gnodesep=1.0 classes_myproject.dot  -o docs/classes/classes.png

# 4 – (Optional) quick-and-simple variant
pyreverse -o png -p myproject -AS .
mv classes_myproject.png packages_myproject.png docs/classes/

## Configuration

### User Configuration

Users are configured in the `leetcode_accountability/users_data.json` file. This file contains user information including:

- LeetCode username
- Splitwise ID and group ID
- Email address
- Minimum required questions per week
- Active status

Example user configuration:

```json
{
  "username": {
    "name": "username",
    "leetcode_id": "leetcode_username",
    "splitwise_id": "12345678",
    "email_address": "user@example.com",
    "splitwise_group_id": "87654321",
    "min_questions": 7,
    "is_active": 1
  }
}

Managing Users

To add a new user:

  1. Add a new entry to the users_data.json file following the format above
  2. Set is_active to 1 to include them in the weekly accountability check

To deactivate a user:

  1. Set their is_active value to 0 in the users_data.json file

To modify user settings:

  1. Edit the corresponding values in the users_data.json file
  2. Changes will take effect the next time the application runs

Environment Variables

Create a .env file in the root directory with the following variables:

SPLITWISE_API_KEY=your_splitwise_api_key

GitHub Actions

The repository includes two automated workflows:

  1. LeetCode Accountability Weekly Run (weekly-run.yml):

    • Runs automatically every Monday at 6 AM London time (5 AM UTC)
    • Can also be triggered manually via workflow_dispatch
    • Executes the weekly accountability check for all active users
    • Runs the weekly-run CLI command which charges users for missed questions via Splitwise and generates statistics
  2. LeetCode Stats Report (stats-report.yml):

    • Runs automatically every Monday at 6 AM London time (5 AM UTC)
    • Can be triggered manually with customizable inputs:
      • usernames: Space-separated LeetCode usernames (default: 'bosire123 seth222 osagiog ioByte')
      • days: Number of days to look back (default: 7)
    • Generates a statistics report for the specified users over the specified time period
    • Runs the stats CLI command with the provided parameters

These GitHub Actions automate the accountability and reporting processes, ensuring regular tracking of LeetCode activity without manual intervention.

License

MIT

About

Keep you accountable to coding practice

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages