A Python package for tracking LeetCode problem-solving activity across multiple users and holding them accountable.
Weekly Run Terminal Output | Splitwise Multiple Expenses | Splitwise Expense Details |
---|---|---|
![]() |
![]() |
![]() |
- 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
- Clone this repository
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install the required dependencies from requirements.txt:
pip install -r requirements.txt
- Set up your environment variables (see Configuration section)
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:
- Run
source ~/.bashrc
to reload your shell configuration - Use
stats
to get stats for all active users for the current week - Use
stats username
to get stats for a specific user for the current week
The package provides two main commands:
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
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
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/
.
# 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
}
}
To add a new user:
- Add a new entry to the
users_data.json
file following the format above - Set
is_active
to1
to include them in the weekly accountability check
To deactivate a user:
- Set their
is_active
value to0
in theusers_data.json
file
To modify user settings:
- Edit the corresponding values in the
users_data.json
file - Changes will take effect the next time the application runs
Create a .env
file in the root directory with the following variables:
SPLITWISE_API_KEY=your_splitwise_api_key
The repository includes two automated workflows:
-
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
-
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.
MIT