putnam

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package putnam is the library behind the putnam command line: the HTTP client, request shaping, and typed data models for the Putnam Competition archive at kskedlaya.org/putnam-archive/.

The Client sets a real User-Agent, paces requests so a busy session stays polite, and retries transient failures (429 and 5xx) with exponential backoff.

Index

Constants

View Source
const BaseURL = "https://kskedlaya.org/putnam-archive"

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "Mozilla/5.0 (compatible; putnam-cli/dev; +https://github.com/tamnd/putnam-cli)"

DefaultUserAgent identifies the client to the site.

View Source
const Host = "kskedlaya.org"

Host is the site this client talks to, and the host the URI driver in domain.go claims.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to kskedlaya.org/putnam-archive/ over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Editions

func (c *Client) Editions(ctx context.Context, limit int) ([]Edition, error)

Editions fetches all Putnam editions by parsing the archive index page. Results are sorted descending by year (newest first). limit <= 0 means no limit.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tunable parameters for the client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults: 300 ms between requests, 30 s timeout, 3 retries.

type Domain

type Domain struct{}

Domain is the Putnam archive driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every Putnam operation onto app.

type Edition

type Edition struct {
	Rank         int    `json:"rank"          table:"RANK" kit:"id"`
	Year         int    `json:"year"          table:"YEAR"`
	ProblemsURL  string `json:"problems_url"  table:"PROBLEMS_URL"`
	SolutionsURL string `json:"solutions_url" table:"SOLUTIONS_URL"`
	WinnersURL   string `json:"winners_url"   table:"WINNERS_URL"`
	ResultsURL   string `json:"results_url"   table:"RESULTS_URL"`
}

Edition represents one year of the Putnam Mathematical Competition.

Jump to

Keyboard shortcuts

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