fetch

package
v0.0.0-...-6504193 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultFetcher = Fetcher{
	FetchPage:            scraperGetDoc,
	FetchPageWithClient:  scraperGetDocWithClient,
	FetchCommentRevision: fetchCommentRevision,
	FetchAvatar:          fetchAvatar,
}

DefaultFetcher is the default fetcher that fetches data from Codeforces web and API.

Functions

This section is empty.

Types

type BlogInfo

type BlogInfo struct {
	Title        string
	Content      string
	Images       []string
	CreationTime time.Time
	AuthorHandle string
	AuthorAvatar string
	AuthorColor  int
	Rating       int
	URL          string
}

BlogInfo contains blog information.

func Blog

func Blog(ctx context.Context, url string) (*BlogInfo, error)

Blog fetches blog information using the DefaultFetcher.

type BlogURLMatch

type BlogURLMatch struct {
	URL       string
	CommentID string
}

BlogURLMatch contains matched information for a blog URL.

func ParseBlogURLs

func ParseBlogURLs(s string) []*BlogURLMatch

ParseBlogURLs parses Codeforces blog URLS from the given string.

type CommentInfo

type CommentInfo struct {
	Content       string
	Images        []string
	BlogTitle     string
	CreationTime  time.Time
	AuthorHandle  string
	AuthorAvatar  string
	AuthorColor   int
	RevisionCount int
	Revision      int
	Rating        int
	URL           string
}

CommentInfo contains comment information.

type CommentInfoGetter

type CommentInfoGetter func(revision int) (*CommentInfo, error)

CommentInfoGetter is a function that returns the comment info for a given revision.

func Comment

func Comment(
	ctx context.Context,
	url string,
	commentID string,
) (revisionCount int, getter CommentInfoGetter, err error)

Comment fetches comment information using the DefaultFetcher.

type Fetcher

type Fetcher struct {
	FetchPage            func(ctx context.Context, url string) (*goquery.Document, error)
	FetchPageWithClient  func(ctx context.Context, url string, client *http.Client) (*goquery.Document, error)
	FetchCommentRevision func(ctx context.Context, commentID string, revision int, csrfToken string, client *http.Client) (*goquery.Document, error)
	FetchAvatar          func(ctx context.Context, handle string) (string, error)
}

Fetcher is a Codeforces info fetcher.

func (*Fetcher) Blog

func (f *Fetcher) Blog(ctx context.Context, url string) (*BlogInfo, error)

Blog fetches blog information. The given URL must be a valid blog URL.

Scrapes instead of using the API because a preview will be added but the blog content is not available through the API.

func (*Fetcher) Comment

func (f *Fetcher) Comment(
	ctx context.Context,
	url string,
	commentID string,
) (revisionCount int, getter CommentInfoGetter, err error)

Comment fetches comment information. The given URL must be a valid comment URL. A CommentInfoGetter is returned. The last revision is immediately available, other revisions are fetched lazily when the CommentInfoGetter is called.

Scrapes instead of using the API because - It's just easier, the comment and author details are together. - Some comments in Russian locale seems to be missing from the API. - Scraping allows access to different revisions.

func (*Fetcher) Problem

func (f *Fetcher) Problem(ctx context.Context, url string) (*ProblemInfo, error)

Problem fetches problem information. The given URL must be a valid problem URL. TODO: Handle URLs like https://codeforces.com/gym/101002/K, which redirect to a page with the pdf of statements.

func (*Fetcher) Profile

func (f *Fetcher) Profile(ctx context.Context, url string) (*ProfileInfo, error)

Profile fetches user profile information. The given URL must be a valid profile URL.

Scrapes instead of using API because

  1. If this is an old handle, it will be redirected to the new handle but the API errors out.
  2. Scraped data shows "Headquarters" rank and black color sometimes which you don't get from the API. So a preview generated by scraping better represents what one will see on opening the link.

func (*Fetcher) Submission

func (f *Fetcher) Submission(ctx context.Context, url string) (*SubmissionInfo, error)

Submission fetches the submission source code and accompanying information. The given URL must be a valid submission URL.

type ProblemInfo

type ProblemInfo struct {
	Name          string
	ContestName   string
	ContestStatus string
	URL           string
}

ProblemInfo contains problem information.

func Problem

func Problem(ctx context.Context, url string) (*ProblemInfo, error)

Problem fetches problem information using the DefaultFetcher.

type ProblemURLMatch

type ProblemURLMatch struct {
	URL string
}

ProblemURLMatch contains matched information for a problem URL.

func ParseProblemURLs

func ParseProblemURLs(s string) []*ProblemURLMatch

ParseProblemURLs parses Codeforces problem URLS from the given string.

type ProfileInfo

type ProfileInfo struct {
	Handle    string
	Rating    int
	MaxRating int
	Rank      string
	Color     int
	Avatar    string
	URL       string
}

ProfileInfo contains profile information.

func Profile

func Profile(ctx context.Context, url string) (*ProfileInfo, error)

Profile fetches user profile information using the DefaultFetcher.

type ProfileURLMatch

type ProfileURLMatch struct {
	URL string
}

ProfileURLMatch contains matched information for a profile URL.

func ParseProfileURLs

func ParseProfileURLs(s string) []*ProfileURLMatch

ParseProfileURLs parses Codeforces profile URLS from the given string.

type SubmissionInfo

type SubmissionInfo struct {
	ID string

	// These are mutually exclusive.
	Author      *SubmissionInfoAuthor
	AuthorTeam  *SubmissionInfoTeam
	AuthorGhost string

	Problem         string
	Language        string
	Verdict         string
	ParticipantType string
	SentTime        time.Time
	Content         string
	URL             string
}

SubmissionInfo contains submission information.

func Submission

func Submission(ctx context.Context, url string) (*SubmissionInfo, error)

Submission fetches submission information using the DefaultFetcher.

type SubmissionInfoAuthor

type SubmissionInfoAuthor struct {
	Handle string
	Color  int
}

SubmissionInfoAuthor contains submission author information.

type SubmissionInfoTeam

type SubmissionInfoTeam struct {
	Name    string
	Authors []*SubmissionInfoAuthor
}

SubmissionInfoTeam contains submission author team information.

type SubmissionURLMatch

type SubmissionURLMatch struct {
	URL       string
	LineBegin int
	LineEnd   int
}

SubmissionURLMatch contains matched information for a submission URL.

func ParseSubmissionURLs

func ParseSubmissionURLs(s string) []*SubmissionURLMatch

ParseSubmissionURLs parses Codeforces submission URLs from the given string.

Jump to

Keyboard shortcuts

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