Skip to main content

A CLI tool to automate competitive programming workflow - fetch, test, and submit solutions

Project description

slave-cp

A powerful CLI tool that automates your competitive programming workflow โ€” fetch problems, test locally, and auto-submit solutions.

PyPI version Python 3.7+ License: MIT


โœจ Features

  • ๐Ÿš€ Quick Setup โ€” One command to initialize your workspace and credentials
  • ๐ŸŒ Multi-Platform Support โ€” Works with Codeforces and CodeChef
  • ๐Ÿ” Auto-Fetch โ€” Automatically scrapes problems and test cases
  • ๐Ÿงช Local Testing โ€” Run solutions against sample inputs with rich diff tables
  • ๐Ÿ“ค Auto-Submit โ€” Submit directly from terminal with real-time verdict tracking
  • ๐ŸŽจ Rich Terminal UI โ€” Beautiful colored output with status indicators
  • ๐Ÿ”ง 23 Languages Supported โ€” From C++ to Rust, Python to Haskell

๐Ÿ“ฆ Installation

pip install slave-cp

Requirements:

  • Python 3.7 or higher
  • Compiler/interpreter for your chosen language (e.g., g++ for C++, python for Python)

๐Ÿš€ Quick Start

1. Initialize Your Workspace

slave-cp init ~/competitive

This will:

  • Set your workspace directory
  • Save Codeforces credentials (handle & password)
  • Save CodeChef credentials (handle & password)
  • Set your default programming language

2. Fetch a Contest

Codeforces:

slave-cp fetch CF1234

CodeChef:

slave-cp fetch CC-START001

This creates a folder with all problems and their test cases:

CF1234/
โ”œโ”€โ”€ A/
โ”‚   โ”œโ”€โ”€ input1.txt
โ”‚   โ”œโ”€โ”€ output1.txt
โ”‚   โ”œโ”€โ”€ input2.txt
โ”‚   โ””โ”€โ”€ output2.txt
โ”œโ”€โ”€ B/
โ”‚   โ”œโ”€โ”€ input1.txt
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ ...

3. Write Your Solution

Create your solution file in the problem folder:

cd CF1234/A
touch solution.cpp  # or .py, .java, etc.

4. Test Locally

slave-cp run A

Or with explicit contest ID:

slave-cp run A --contest CF1234

Output:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Test Case 1                                        โœ… AC  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Input:     5 3                                            โ”‚
โ”‚ Expected:  8                                              โ”‚
โ”‚ Got:       8                                              โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

All test cases passed! ๐ŸŽ‰
Submit to Codeforces? [y/N]:

5. Submit (Optional)

If all tests pass, you'll be prompted to submit. Type y to submit directly to the platform.


๐Ÿ“š Commands

Command Description
slave-cp init <path> Initialize workspace and save credentials
slave-cp fetch <contest-id> Fetch problems and test cases from a contest
slave-cp run <problem> Test your solution against sample inputs
slave-cp run <problem> --contest <id> Test with explicit contest ID
slave-cp config Display current configuration
slave-cp list List all contests in workspace
slave-cp check Check installed compilers/interpreters
slave-cp --help Show help message

๐ŸŒ Supported Platforms

Codeforces

  • Contest format: CF<contest-number> (e.g., CF1234)
  • Scrapes problems using requests + BeautifulSoup
  • Auto-login with saved credentials
  • Real-time verdict polling

CodeChef

  • Contest format: CC-<contest-code> (e.g., CC-START001)
  • Uses Selenium with headless Chrome
  • Supports practice problems and contests
  • Automated CodeMirror injection for submission

๐Ÿ’ป Supported Languages (23)

Auto-detected by file extension:

Language Extension Compiler/Interpreter Required
C++ .cpp g++
C .c gcc
Python .py python or python3
Java .java javac + java
Kotlin .kt kotlinc + kotlin
Go .go go
Rust .rs rustc
C# .cs dotnet-script
Ruby .rb ruby
JavaScript .js node
TypeScript .ts ts-node
Haskell .hs ghc
Scala .scala scalac + scala
D .d dmd
Pascal .pas fpc
Perl .pl perl
PHP .php php
Swift .swift swift
Lua .lua lua
R .r Rscript
Dart .dart dart
F# .fs dotnet fsi
PyPy .pypy pypy or pypy3

Run slave-cp check to verify which languages are available on your system.


โš™๏ธ Configuration

Configuration is stored at ~/.slave-cp/config.json:

{
  "workspace": "/Users/username/competitive",
  "language": "cpp",
  "codeforces": {
    "handle": "tourist",
    "password": "your-password"
  },
  "codechef": {
    "handle": "gennady.korotkevich",
    "password": "your-password"
  }
}

View current config:

slave-cp config

Update workspace or credentials:

slave-cp init ~/new-workspace

๐Ÿงช Testing Workflow

Verdicts

Verdict Symbol Meaning
AC โœ… Accepted โ€” correct output
WA โŒ Wrong Answer โ€” output mismatch
TLE โฑ๏ธ Time Limit Exceeded (>5s)
RE ๐Ÿ’ฅ Runtime Error โ€” program crashed
CE ๐Ÿ”ง Compilation Error โ€” code didn't compile

Diff Table

When output doesn't match:

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Test Case 2                                        โŒ WA  โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Input:     10 20 30                                       โ”‚
โ”‚ Expected:  60                                             โ”‚
โ”‚ Got:       50                                             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ”ง Troubleshooting

HTTP 403 Error on Codeforces Fetch

Problem: Codeforces blocks the scraper

Solution: This will be fixed in the next version (0.1.1). For now, try:

  • Running the command again (sometimes transient)
  • Using a VPN if your IP is rate-limited

Wrong/Empty Credentials Accepted

Problem: Invalid credentials saved without validation

Solution: Fixed in version 0.1.1. Meanwhile, manually edit ~/.slave-cp/config.json to ensure credentials are correct.

Selenium/Chrome Issues (CodeChef)

Problem: chromedriver not found or browser errors

Solution:

# macOS
brew install chromedriver

# Ubuntu/Debian
sudo apt-get install chromium-chromedriver

# Windows
Download from https://chromedriver.chromium.org/

Compiler Not Found

Problem: g++: command not found

Solution:

# macOS
xcode-select --install

# Ubuntu/Debian
sudo apt-get install build-essential

# Windows
Install MinGW or use WSL

Check installed compilers:

slave-cp check

๐Ÿ“– Advanced Usage

Custom Time Limit

By default, solutions timeout after 5 seconds. This is hardcoded but can be adjusted in future versions.

Multiple Solutions

You can have multiple solution files (e.g., solution.cpp, brute.cpp) in the same problem folder. slave-cp run will use the first one it finds matching your default language.

Manual Test Cases

Add your own test cases by creating input{n}.txt and output{n}.txt pairs in the problem folder.


๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

Development setup:

git clone https://github.com/block-plant/slave-cp.git
cd slave-cp
pip install -e .[dev]
pytest

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.


๐Ÿ‘ค Author

Ayush Kunwar Singh (@block-plant)


๐Ÿ™ Acknowledgments


๐Ÿ“Š Project Status

  • โœ… Live on PyPI: pip install slave-cp
  • โœ… Codeforces support
  • โœ… CodeChef support
  • โœ… 23 languages supported
  • ๐Ÿšง Version 0.1.1 coming soon with bug fixes

๐Ÿ”— Links


Happy Coding! ๐Ÿš€

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slave_cp-0.1.5.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slave_cp-0.1.5-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file slave_cp-0.1.5.tar.gz.

File metadata

  • Download URL: slave_cp-0.1.5.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for slave_cp-0.1.5.tar.gz
Algorithm Hash digest
SHA256 7dc2346c98e0fec1314d7b379e7671dd726fc02c60e62432648ac8b0d16ae09d
MD5 daadaa2670e9cdff479b57d8c123725d
BLAKE2b-256 07275f7a2c4e77fd79f8038567a20d7d4a1122ea5253a6f7a00a6e374a073eab

See more details on using hashes here.

File details

Details for the file slave_cp-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: slave_cp-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for slave_cp-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4c73bf3594d3118f9ed2d8b84b5ec52d52f9f0a1bdc47e937b5b8ae94b8446
MD5 5ae39c0be20fc01468f333ac73752692
BLAKE2b-256 0485389c556f67c9b0db3a95ab909734869ee849f7758237cbcae478f15ac29c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page