-
Notifications
You must be signed in to change notification settings - Fork 548
/
readme.go
43 lines (32 loc) · 838 Bytes
/
readme.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
)
func makeREADME(lc *leetcode) {
file := "README.md"
os.Remove(file)
template := `%s
## 答题进度:%d%%
> 仅含免费题
%s
## 参考解答
%s
%s
`
headFormat := string(read("README_HEAD.md"))
head := fmt.Sprintf(headFormat, lc.Username, lc.Username, lc.Ranking, lc.Username)
// 没有提供 Golang 解答方法的题目
canNotSolve := 2
acceptedPercent := lc.Categories[len(lc.Categories)-1].Total.Solved * 100 / (lc.Categories[len(lc.Categories)-1].Total.Total - canNotSolve)
count := lc.Categories.String()
accepted := lc.Problems.acceptedString()
tail := read("README_TAIL.md")
content := fmt.Sprintf(template, head, acceptedPercent, count, accepted, tail)
err := ioutil.WriteFile(file, []byte(content), 0755)
if err != nil {
log.Fatal(err)
}
}