codeforces

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassContest = "contest"
	ClassGroup   = "group"
	ClassGym     = "gym"
)

Class type of contest.

View Source
const (
	RegistrationClosed    = 0
	RegistrationOpen      = 1
	RegistrationDone      = 2
	RegistrationNotExists = -1
)

Contest registration status of current session.

View Source
const (
	SolveAccepted     = 1
	SolveRejected     = 0
	SolveNotAttempted = -1
)

Different values of 'SolveStatus'.

Variables

View Source
var (
	ErrInvalidSpecifier   = fmt.Errorf("invalid specifier data")
	ErrInvalidCredentials = fmt.Errorf("invalid login credentials")
)

Set errors returned by library.

View Source
var (
	// LanguageID represents all available languages with ids.
	LanguageID = map[string]string{
		"GNU GCC C11 5.1.0":                "43",
		"Clang++17 Diagnostics":            "52",
		"GNU G++11 5.1.0":                  "42",
		"GNU G++14 6.4.0":                  "50",
		"GNU G++17 7.3.0":                  "54",
		"Microsoft Visual C++ 2010":        "2",
		"Microsoft Visual C++ 2017":        "59",
		"GNU G++17 9.2.0 (64 bit, msys 2)": "61",
		"C# Mono 5.18":                     "9",
		"D DMD32 v2.086.0":                 "28",
		"Go 1.12.6":                        "32",
		"Haskell GHC 8.6.3":                "12",
		"Java 11.0.5":                      "60",
		"Java 1.8.0_162":                   "36",
		"Kotlin 1.3.10":                    "48",
		"OCaml 4.02.1":                     "19",
		"Delphi 7":                         "3",
		"Free Pascal 3.0.2":                "4",
		"PascalABC.NET 3.4.2":              "51",
		"Perl 5.20.1":                      "13",
		"PHP 7.2.13":                       "6",
		"Python 2.7.15":                    "7",
		"Python 3.7.2":                     "31",
		"PyPy 2.7 (7.2.0)":                 "40",
		"PyPy 3.6 (7.2.0)":                 "41",
		"Ruby 2.0.0p645":                   "8",
		"Rust 1.35.0":                      "49",
		"Scala 2.12.8":                     "20",
		"JavaScript V8 4.8.0":              "34",
		"Node.js 9.4.0":                    "55",
		"ActiveTcl 8.5":                    "14",
		"Io-2008-01-07 (Win32)":            "15",
		"Pike 7.8":                         "17",
		"Befunge":                          "18",
		"OpenCobol 1.0":                    "22",
		"Factor":                           "25",
		"Secret_171":                       "26",
		"Roco":                             "27",
		"Ada GNAT 4":                       "33",
		"Mysterious Language":              "38",
		"FALSE":                            "39",
		"Picat 0.9":                        "44",
		"GNU C++11 5 ZIP":                  "45",
		"Java 8 ZIP":                       "46",
		"J":                                "47",
		"Microsoft Q#":                     "56",
		"Text":                             "57",
	}

	// LanguageExtn corresponds to file extension of
	// given language source code.
	LanguageExtn = map[string]string{
		"GNU C11":               ".c",
		"Clang++17 Diagnostics": ".cpp",
		"GNU C++0x":             ".cpp",
		"GNU C++":               ".cpp",
		"GNU C++11":             ".cpp",
		"GNU C++14":             ".cpp",
		"GNU C++17":             ".cpp",
		"MS C++":                ".cpp",
		"MS C++ 2017":           ".cpp",
		"GNU C++17 (64)":        ".cpp",
		"Mono C#":               ".cs",
		"D":                     ".d",
		"Go":                    ".go",
		"Haskell":               ".hs",
		"Kotlin":                ".kt",
		"Ocaml":                 ".ml",
		"Delphi":                ".pas",
		"FPC":                   ".pas",
		"PascalABC.NET":         ".pas",
		"Perl":                  ".pl",
		"PHP":                   ".php",
		"Python 2":              ".py",
		"Python 3":              ".py",
		"PyPy 2":                ".py",
		"PyPy 3":                ".py",
		"Ruby":                  ".rb",
		"Rust":                  ".rs",
		"JavaScript":            ".js",
		"Node.js":               ".js",
		"Q#":                    ".qs",
		"Java":                  ".java",
		"Java 6":                ".java",
		"Java 7":                ".java",
		"Java 8":                ".java",
		"Java 9":                ".java",
		"Java 10":               ".java",
		"Java 11":               ".java",
		"Tcl":                   ".tcl",
		"F#":                    ".fs",
		"Befunge":               ".bf",
		"Pike":                  ".pike",
		"Io":                    ".io",
		"Factor":                ".factor",
		"Cobol":                 ".cbl",
		"Secret_171":            ".secret_171",
		"Ada":                   ".adb",
		"FALSE":                 ".f",
		"":                      ".txt",
	}
)
View Source
var (

	// SessCln should be set to desired session configuration.
	// Ensure cookies, proxy protocol etc are set up if reqd.
	SessCln *http.Client
)

Functions

func Login

func Login(usr, passwd string) (string, error)

Login tries logging into codeforces using credentials passed. Checks if any active session exists (in SessCln) before logging in. If you wish to overwrite currently logged in session, set cookies of SessCln to nil before logging in.

If login is successful, returns user handle of now logged in session. Otherwise, if login fails, returns ErrInvalidCredentials as error.

By default, option 'remember me' is checked, ensuring the session has expiry period of one month from date of last login.

func LoginPage added in v1.4.0

func LoginPage() string

LoginPage returns link to login page

Types

type Args

type Args struct {
	Contest string
	Problem string
	Class   string
	Group   string
}

Args holds specifier details parsed by Parse() function. Provides methods to access value of specifiers (read-only).

func Parse

func Parse(str string) (Args, error)

Parse passed in specifier string to new Args struct. Validates parsed args and returns error if any.

List of valid specifiers can be viewed at github.com/cp-tools/codeforces/wiki.

func (Args) ContestsPage added in v1.4.0

func (arg Args) ContestsPage() (link string)

ContestsPage returns link to all contests page (group/gym/contest)

func (Args) CountdownPage added in v1.4.0

func (arg Args) CountdownPage() (link string)

CountdownPage returns link to countdown in contest

func (Args) DashboardPage added in v1.4.0

func (arg Args) DashboardPage() (link string)

DashboardPage returns link to dashboard of contest

func (Args) GetContests

func (arg Args) GetContests(omitFinishedContests bool) ([]Contest, error)

GetContests extracts contest/gym/group contests data based on specified data in Args. Expects arg.Class to be configured to fetch respective contest details.

Set 'omitFinishedContests' to true to exclude finished contests.

func (Args) GetCountdown

func (arg Args) GetCountdown() (time.Duration, error)

GetCountdown parses and returns duration type for countdown in specified contest to end. If countdown has already ended, returns 0. Extracts data from .../contest/<contest>/countdown.

func (Args) GetDashboard added in v1.1.1

func (arg Args) GetDashboard() (Dashboard, error)

GetDashboard parses and returns useful info from contest dashboard page.

func (Args) GetProblems

func (arg Args) GetProblems() ([]Problem, error)

GetProblems parses problem(s) details along with sample tests. If problem field is not specified, extracts details of all problems in the contest.

In some older contests, complete problemset page is not supported. Preferably fallback to parsing individual problems if entire parsing fails.

Doesn't fetch 'SolveStatus' and 'SolveCount' of problem. Use GetDashboard() to fetch these info fields.

func (Args) GetSubmissions

func (arg Args) GetSubmissions(handle string) ([]Submission, error)

GetSubmissions parses and returns all submissions data in specified args of given user. Fetches details of all submissions of handle if args is nil.

If handle is not set, fetches submissions of currently active user session.

Due to a bug on codeforces, submissions in groups are not supported.

func (Args) ProblemsPage added in v1.4.0

func (arg Args) ProblemsPage() (link string)

ProblemsPage returns link to problem(s) page in contest

func (Args) RegisterForContest

func (arg Args) RegisterForContest() (*RegisterInfo, error)

RegisterForContest parses and returns registration terms of contest specified in args.

Provides callback method to register current user session in contest. If registration was successful, returns nil error.

func (Args) RegisterPage added in v1.4.0

func (arg Args) RegisterPage() (link string)

RegisterPage returns link to registration (nor virtual reg) in contest

func (Args) String added in v1.5.1

func (arg Args) String() string

func (Args) SubmissionsPage added in v1.4.0

func (arg Args) SubmissionsPage(handle string) (link string)

SubmissionsPage returns link to user submissions

func (Args) SubmitSolution

func (arg Args) SubmitSolution(langID string, source string) error

SubmitSolution submits source code to specifed problem. langID is codeforces specified id of language to submit in. View cp-tools/codeforces.wiki for list of valid ID's. Source is code text to submit.

If submission completed successfully, returns nil error.

type Contest

type Contest struct {
	Name        string
	Writers     []string
	StartTime   time.Time
	Duration    time.Duration
	RegCount    int
	RegStatus   int
	Description []string
	Arg         Args
}

Contest holds details from contest row from contests table.

type Dashboard added in v1.1.1

type Dashboard struct {
	Name      string
	Problem   []Problem
	Countdown time.Duration
	// href link => description
	Material map[string]string
}

Dashboard holds details from contest dashboard.

type Problem

type Problem struct {
	Name        string
	TimeLimit   string
	MemoryLimit string
	InpStream   string
	OutStream   string
	SampleTests []SampleTest
	SolveCount  int
	SolveStatus int
	Arg         Args
}

Problem data is parsed to this struct.

type RegisterInfo

type RegisterInfo struct {
	Name     string
	Terms    string
	Register func() error
}

RegisterInfo holds data pertaining to contest registration along with a callback function to register in the said contest.

type SampleTest

type SampleTest struct {
	Input  string
	Output string
}

SampleTest maps sample input to sample output.

type Submission

type Submission struct {
	ID        string
	When      time.Time
	Who       string
	Problem   string
	Language  string
	Verdict   string
	Time      string
	Memory    string
	IsJudging bool
	Arg       Args
}

Submission holds submission data

func (Submission) GetSourceCode

func (sub Submission) GetSourceCode() (string, error)

GetSourceCode parses and returns source code of submission as specified in the method. Has an auto sleep cycle of 4 seconds to handle http error "Too Many Requests".

Due to a bug on codeforces, groups are not supported.

func (Submission) SourceCodePage added in v1.4.0

func (sub Submission) SourceCodePage() (link string)

SourceCodePage returns link to solution submission

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL