Documentation ¶
Index ¶
- Variables
- type BlogInfo
- type BlogURLMatch
- type CommentInfo
- type CommentInfoGetter
- type Fetcher
- func (f *Fetcher) Blog(ctx context.Context, url string) (*BlogInfo, error)
- func (f *Fetcher) Comment(ctx context.Context, url string, commentID string) (revisionCount int, getter CommentInfoGetter, err error)
- func (f *Fetcher) Problem(ctx context.Context, url string) (*ProblemInfo, error)
- func (f *Fetcher) Profile(ctx context.Context, url string) (*ProfileInfo, error)
- func (f *Fetcher) Submission(ctx context.Context, url string) (*SubmissionInfo, error)
- type ProblemInfo
- type ProblemURLMatch
- type ProfileInfo
- type ProfileURLMatch
- type SubmissionInfo
- type SubmissionInfoAuthor
- type SubmissionInfoTeam
- type SubmissionURLMatch
Constants ¶
This section is empty.
Variables ¶
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.
type BlogURLMatch ¶
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.
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 ¶
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 ¶
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 ¶
Profile fetches user profile information. The given URL must be a valid profile URL.
Scrapes instead of using API because
- If this is an old handle, it will be redirected to the new handle but the API errors out.
- 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 ¶
Submission fetches the submission source code and accompanying information. The given URL must be a valid submission URL.
type ProblemInfo ¶
ProblemInfo contains problem information.
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.
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 ¶
SubmissionInfoAuthor contains submission author information.
type SubmissionInfoTeam ¶
type SubmissionInfoTeam struct { Name string Authors []*SubmissionInfoAuthor }
SubmissionInfoTeam contains submission author team information.
type SubmissionURLMatch ¶
SubmissionURLMatch contains matched information for a submission URL.
func ParseSubmissionURLs ¶
func ParseSubmissionURLs(s string) []*SubmissionURLMatch
ParseSubmissionURLs parses Codeforces submission URLs from the given string.