npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@proghours/crawler

v0.0.4

Published

`@proghours/crawler` is a library designed to extract information from programming problems available on various online judges. It pulls data, such as problem `name`, `problem_id`, `contest_id`, `tag`, `difficulty` etc, by fetching the information from th

Downloads

6

Readme

@proghours/crawler

@proghours/crawler is a library designed to extract information from programming problems available on various online judges. It pulls data, such as problem name, problem_id, contest_id, tag, difficulty etc, by fetching the information from the given problem URL. It can also fetch user submissions from supported online judges.

In cases where an API is not available, @proghours/crawler utilizes web crawling techniques to gather the necessary data. By integrating @proghours/crawler with progHours, we are able to easily extract the necessary data we needed for the system.

Installation

The library is available online and can be installed via npm

npm i @proghours/crawler

Basic Usage

Fetch information about a problem

import { fetchProblem } from "@proghours/crawler";

async function main() {
  const data = await fetchProblem(
    "https://codeforces.com/problemset/problem/1879/D"
  );

  // do something with the data
  console.log(data);
}

main();

If you are using CommonJS modules, you can also use the require function to import the library. The returned object from fetchProblem will satisfy the following interface.

interface ProblemData {
  pid: string;
  name: string;
  url: string;
  tags: string[];
  difficulty: number;
}

Fetch Submissions of an User

import { fetchUserSubmissions } from "@proghours/crawler";

async function main() {
  const data = await fetchUserSubmissions('CODEFORCES', {
    handle: "naimul_haque",
  });

  // data is of type CfSubmissions
  // do something with the data
  console.log(data.totalSolved);
  console.log(data.submissions);
}

main();

In order to fetch submissions from CodeChef, we need to pass in the 2 extra properties clientId and secret, so that our crawler can talk with the CodeChef APIs.

import { fetchUserSubmissions } from "@proghours/crawler";

async function main() {
  const data = await fetchUserSubmissions('CODECHEF', {
    handle: "naimul_haque",
    clientID: "CODECHEF_API_CLIENT_ID",
    secret: "CODECHEF_API_SECRET"
  });

  // data is of type CcSubmissions
  // do something with the data
  console.log(data.totalSolved);
  console.log(data.submissions);
}

main();

Additionally, you can also pass an optional contestId to fetch user submissions from only that contestId. This works simillarly for CodeChef as well.

import { fetchUserSubmissions } from "@proghours/crawler";

async function main() {
  const data = await fetchUserSubmissions('CODEFORCES', {
    handle: "naimul_haque",
    contestId: "1742"
  });

  // data is of type CfSubmissions
  // do something with the data
  console.log(data.totalSolved);
  console.log(data.submissions);
}

main();

Currently, fetchUserSubmissions only supports Codeforces and CodeChef. The returned object from fetchUserSubmissions will return one of the following interfaces. TypeScript will map the proper return type, based on the first parameter.

type CfSubmissions = {
  totalSolved: number;
  submissions: Array<{
    id: number;
    pid: string;
    name: string;
    url: string;
    difficulty: number;
    tags: string[];
    contestId: number;
    createdAt: Date;
    verdict: Verdict;
  }>;
};

type CcSubmissions = {
  totalSolved: number;
  submissions: Array<{
    id: number;
    pid: string;
    url: string;
    contestId: string;
    createdAt: Date;
    verdict: Verdict;
    solvedDuringContest: boolean;
  }>;
};

Online Judge Support

The library currently supports 14 different online judges.

  1. Codeforces
  2. CodeChef
  3. CSES
  4. Online Judge
  5. Toph
  6. SPOJ
  7. HackerRank
  8. LightOJ
  9. AtCoder
  10. EOlymp
  11. LeetCode
  12. Timus Online Judge
  13. CodeToWin
  14. Kattis

Test Coverage

We have 100% test coverage for the library, the tests could break if the 3rd party APIs or web pages changes.

Each online judge is covered by individual test files. For example, the codeforces.spec.ts file contains test cases specifically designed for the Codeforces crawler. Similarly, we have .spec.ts files for all other crawlers.

Running All Tests

To run all the tests project, you can execute the following command:

nx run crawler:test

Running Individual Test Files

If you wish to run tests for a specific online judge, you can use the following command:

nx run crawler:test --testFile=libs/crawler/src/tests/codeforces.spec.ts

Simply replace codeforces.spec.ts with the desired test file for the corresponding online judge. This command will execute the specified test file and provide the results.

By running the tests, you can ensure that the library functions as expected and handles various scenarios encountered on different online judges effectively.