 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
- Variables
- func Login(usr, passwd string) (string, error)
- type Args
- func (arg Args) GetContests(omitFinishedContests bool) ([]Contest, error)
- func (arg Args) GetCountdown() (time.Duration, error)
- func (arg Args) GetProblems() ([]Problem, error)
- func (arg Args) GetSubmissions(handle string) ([]Submission, error)
- func (arg Args) RegisterForContest() (*RegisterInfo, error)
- func (arg Args) SubmitSolution(langID string, source string) error
 
- type Contest
- type Problem
- type RegisterInfo
- type SampleTest
- type Submission
Constants ¶
const ( ClassContest = "contest" ClassGroup = "group" ClassGym = "gym" )
Class type of contest.
const ( RegistrationClosed = 0 RegistrationOpen = 1 RegistrationDone = 2 RegistrationNotExists = -1 )
Contest registration status of current session.
Variables ¶
var ( ErrInvalidSpecifier = fmt.Errorf("invalid specifier data") ErrInvalidCredentials = fmt.Errorf("invalid login credentials") )
Set errors returned by library.
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", } )
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 ¶
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.
Types ¶
type Args ¶
Args holds specifier details parsed by Parse() function. Provides methods to access value of specifiers (read-only).
func Parse ¶
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) GetContests ¶
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 ¶
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) GetProblems ¶
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.
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.
Due to a bug on codeforces, submissions in groups are not supported.
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) SubmitSolution ¶
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 Problem ¶
type Problem struct {
	Name        string
	TimeLimit   string
	MemoryLimit string
	InpStream   string
	OutStream   string
	SampleTests []SampleTest
	Arg         Args
}
    Problem data is parsed to this struct.
type RegisterInfo ¶
RegisterInfo holds data pertaining to contest registration along with a callback function to register in the said contest.
type SampleTest ¶
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.