gofmt: main.go
This commit is contained in:
parent
7fba45c0a8
commit
5aa133b6af
1 changed files with 68 additions and 68 deletions
|
@ -1,102 +1,102 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
"fmt"
|
||||
"strings"
|
||||
"io/fs"
|
||||
"io"
|
||||
"os"
|
||||
"log"
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Status string `json:"status"`
|
||||
Result Result `json:"result"`
|
||||
Status string `json:"status"`
|
||||
Result Result `json:"result"`
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
Problems []Problem `json:"problems"`
|
||||
ProblemStatistics []ProblemStatistics `json:"problemStatistics"`
|
||||
Problems []Problem `json:"problems"`
|
||||
ProblemStatistics []ProblemStatistics `json:"problemStatistics"`
|
||||
}
|
||||
|
||||
type Problem struct {
|
||||
ContestId int `json:"contestId"`
|
||||
Name string `json:"name"`
|
||||
Index string `json:"index"`
|
||||
Type string `json:"type"`
|
||||
Points float32 `json:"points"`
|
||||
Rating int `json:"rating"`
|
||||
SolvedCount int `json:"solvedCount"`
|
||||
ContestId int `json:"contestId"`
|
||||
Name string `json:"name"`
|
||||
Index string `json:"index"`
|
||||
Type string `json:"type"`
|
||||
Points float32 `json:"points"`
|
||||
Rating int `json:"rating"`
|
||||
SolvedCount int `json:"solvedCount"`
|
||||
}
|
||||
|
||||
type ProblemStatistics struct {
|
||||
ContestId int `json:"contestId"`
|
||||
Index string `json:"index"`
|
||||
SolvedCount int `json:"solvedCount"`
|
||||
ContestId int `json:"contestId"`
|
||||
Index string `json:"index"`
|
||||
SolvedCount int `json:"solvedCount"`
|
||||
}
|
||||
|
||||
var files []string
|
||||
|
||||
func visit(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() && d.Name() == "target" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
files = append(files, strings.TrimSuffix(d.Name(), filepath.Ext(d.Name())))
|
||||
return nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.IsDir() && d.Name() == "target" {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
files = append(files, strings.TrimSuffix(d.Name(), filepath.Ext(d.Name())))
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
resp, err := http.Get("https://codeforces.com/api/problemset.problems")
|
||||
resp, err := http.Get("https://codeforces.com/api/problemset.problems")
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
var response Response
|
||||
if err := json.Unmarshal(body, &response); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
var response Response
|
||||
if err := json.Unmarshal(body, &response); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
err = filepath.WalkDir("../solutions", visit)
|
||||
err = filepath.WalkDir("../solutions", visit)
|
||||
|
||||
var solved []string
|
||||
var solved []string
|
||||
|
||||
for _, p := range response.Result.Problems {
|
||||
for _, i := range files {
|
||||
if i == fmt.Sprintf("%v%v", p.ContestId, p.Index) {
|
||||
text := fmt.Sprintf("- [%v%v %v](https://codeforces.com/problemset/problem/%v/%v)", p.ContestId, p.Index, p.Name, p.ContestId, p.Index)
|
||||
solved = append(solved, text)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, p := range response.Result.Problems {
|
||||
for _, i := range files {
|
||||
if i == fmt.Sprintf("%v%v", p.ContestId, p.Index) {
|
||||
text := fmt.Sprintf("- [%v%v %v](https://codeforces.com/problemset/problem/%v/%v)", p.ContestId, p.Index, p.Name, p.ContestId, p.Index)
|
||||
solved = append(solved, text)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file, err := os.Create("../README.md")
|
||||
if err != nil {
|
||||
fmt.Println("Error creating file:", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
file, err := os.Create("../README.md")
|
||||
if err != nil {
|
||||
fmt.Println("Error creating file:", err)
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
file.WriteString("# Code Forces Solutions\nMy set of solutions to the problems on Code Forces.\n## Solutions\n")
|
||||
file.WriteString("# Code Forces Solutions\nMy set of solutions to the problems on Code Forces.\n## Solutions\n")
|
||||
|
||||
for _, line := range solved {
|
||||
_, err := file.WriteString(line + "\n")
|
||||
if err != nil {
|
||||
fmt.Println("Error writing to file:", err)
|
||||
return
|
||||
}
|
||||
for _, line := range solved {
|
||||
_, err := file.WriteString(line + "\n")
|
||||
if err != nil {
|
||||
fmt.Println("Error writing to file:", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue