Skip to main content

A Python library for interacting with Codeforces API and automating tasks.

Project description

cf-helper Library

A Python library for interacting with the Codeforces API, allowing you to fetch user information, ratings, problems, contests, and more.


Table of Contents


Installation

To use cf-helper, you need to install the library. Ensure you have pip installed on your system.

pip install cf-helper

API Key Setup (Optional)

To access private data via the Codeforces API, you'll need to generate an API key:

  1. Go to Codeforces: Visit Codeforces API Settings.
  2. Create a New API Key: Provide a name for the key. Codeforces will generate:
    • Key: The public part of the API key.
    • Secret: A private part used for signing requests.
  3. Store the Key and Secret:
    • Add your key and secret to a .env file in your project directory:
      key="your_api_key"
      secret="your_api_secret"
      

Usage

Importing the Library

The library provides utilities for easy interaction with the Codeforces API. Simplify your imports using the cf_helper package.

from cf_helper import *
# No need to do below steps if only public functions are used
from dotenv import load_dotenv
import os

load_dotenv()
key = os.getenv("key")
secret = os.getenv("secret")

Examples

Below are examples of various functions provided by the library.

Fetch User Information

handle = "CodeLegendX"
print_user_info(handle)

Fetch User Status

print_user_status(handle, noOfEntries=2)

Fetch User Friends

print_user_friends(handle, key, secret, noOfFriends=2)

Fetch Problems

print_problems(noOfEntries=2, tags="dp", rating=1900)

Fetch Contest Rating Changes

print_rating_changes(contest_id=2040, noOfEntries=2)

Fetch User Contest Rating Change

print_user_rating_change(contest_id=2040, handle="CodeLegendX")

Fetch Accepted Submission

print_submission_link(handle, contestId=2040, index='C')

Fetch Contest Standings

print_contest_standings(contestId=2040, from_index=1, count=5, showUnofficial=True)

Fetch User Standing in Contest

print_user_standing(contestId=2006, handles="tourist;jiangly", showUnofficial=True)

Fetch Upcoming Contests

print_upcoming_contest()

Fetch Virtual Contests

print_virtual_contests(handle="CodeLegendX", contest_type="div2", noOfContest=3, chooseRandom=True)

Fetch Unattempted Problems

print_unattempted_problems(handle="CodeLegendX", tags="dp", rating=1600, noOfEntries=3, chooseRandom=True)

Functions

  • print_user_info(handle): Display user information in a readable format.
  • print_user_status(handle, noOfEntries): Display user submission status.
  • print_user_friends(handle, key, secret, noOfFriends, only_online): Display user friends.
  • print_problems(noOfEntries, tags, rating): Display problems.
  • print_rating_changes(contest_id, noOfEntries): Display contest rating changes.
  • print_user_rating_change(contest_id, handle):: Display user contest rating change.
  • print_submission_link(handle, contestId, index): Display accepted submission link.
  • print_contest_standings(contestId, from_index, count, showUnofficial): Display contest standings.
  • print_user_standing(contestId, handles, showUnofficial): Display standings for specific handles in a contest.
  • print_upcoming_contest(): Display a list of upcoming contests.
  • print_virtual_contests(handle, contest_type, noOfContest, chooseRandom): Display virtual contests suitable for the user.
  • print_unattempted_problems(handle, tags, rating, noOfEntries, chooseRandom): Display unattempted problems with custom filter.

Limitations

  • Public Data Only: Without an API key, only public data is accessible.
  • Rate Limits: The Codeforces API has rate limits. Avoid excessive requests.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

cf_helper-0.2.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

cf_helper-0.2.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file cf_helper-0.2.2.tar.gz.

File metadata

  • Download URL: cf_helper-0.2.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for cf_helper-0.2.2.tar.gz
Algorithm Hash digest
SHA256 347ee02ef44e3c295a6f68dcee18c006e0fdecda69378ec0bb4d3ee27468e2bd
MD5 dae6c4cadaca169fc02c4437b8e418ca
BLAKE2b-256 a30dcb04a052665d5caa9112ba1ddf5e84de56f9dc8d2acb628119b04c04107b

See more details on using hashes here.

File details

Details for the file cf_helper-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: cf_helper-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for cf_helper-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38a9241d0b98d91364ed153fb502e94ef95513ff2b8306af6c5a64e667f34a5f
MD5 ecc0fa2d19b1fb86103cdda1ed525be2
BLAKE2b-256 0b1cae8665cdfd9365bc0b880ac4be1956792e50cd1c0f01fdf6278a7af83c3c

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