Exemple #1
0
// Provides a list of accepted submission records meeting specified criteria.
// If call this function with default value ("" or -1), don't use it when API calling
func SolvedRecordSearchApi(user_id, problem_id, language string, dateBegin, dateEnd int) ([]SolvedRecord, error) {
	q := url.Values{}
	if user_id != "" {
		q.Add("user_id", user_id)
	}
	if problem_id != "" {
		q.Add("problem_id", problem_id)
	}
	if language != "" {
		q.Add("language", language)
	}
	if dateBegin != -1 {
		q.Add("date_begin", strconv.Itoa(dateBegin))
	}
	if dateEnd != -1 {
		q.Add("date_end", strconv.Itoa(dateEnd))
	}
	data, err := http.Get(SolvedRecordSearchUrl, q.Encode())
	if err != nil {
		return nil, err
	}
	r := &struct {
		SolvedRecords []SolvedRecord `xml:"solved"`
	}{}
	fmt.Printf("%v\n", string(data))
	err = xml.Unmarshal(data, r)
	return r.SolvedRecords, err
}
Exemple #2
0
func ProblemSearchApi(id string, status bool) (*Problem, error) {
	q := url.Values{"id": {id}, "status": {strconv.FormatBool(status)}}.Encode()
	data, err := http.Get(ProblemSearchUrl, q)
	if err != nil {
		return nil, err
	}
	p := new(Problem)
	err = xml.Unmarshal(data, p)
	return p, err
}
Exemple #3
0
func UserSearchApi(userId string) (*User, error) {
	data, err := http.Get(UserSearchUrl, url.Values{"id": {userId}}.Encode())
	if err != nil {
		return nil, err
	}

	u := new(User)
	err = xml.Unmarshal(data, u)
	return u, err
}
Exemple #4
0
func ProblemListSearchApi(volume int) ([]Problem, error) {
	q := url.Values{"volume": {strconv.Itoa(volume)}}.Encode()
	data, err := http.Get(ProblemListSearchUrl, q)
	if err != nil {
		return nil, err
	}
	pl := &struct {
		Problems []Problem `xml:"problem"`
	}{}
	err = xml.Unmarshal(data, pl)
	return pl.Problems, err
}