Skip to content

Commit 898bde1

Browse files
committed
delete the not exits problem for gitbook
1 parent be675dd commit 898bde1

File tree

17 files changed

+87
-808
lines changed

17 files changed

+87
-808
lines changed

SUMMARY.md

+5-806
Large diffs are not rendered by default.

cmd/gitbook.go

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package main

cmd/leetcode.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
type LeetCode struct {
4+
UserName string `json:"user_name"`
5+
NumSolved int `json:"num_solved"`
6+
NumTotal int `json:"num_total"`
7+
AcEasy int `json:"ac_easy"`
8+
AcMedium int `json:"ac_medium"`
9+
AcHard int `json:"ac_hard"`
10+
StatStatusPairs []Problem `json:"stat_status_pairs"`
11+
FrequencyHigh int `json:"frequency_high"`
12+
FrequencyMid int `json:"frequency_mid"`
13+
CategorySlug string `json:"category_slug"`
14+
}
15+
16+
// 问题
17+
type Problem struct {
18+
Stat Stat `json:"stat"`
19+
Status bool `json:"status"`
20+
Difficulty Difficulty `json:"difficulty"`
21+
PaidOnly bool `json:"paid_only"`
22+
IsFavor bool `json:"is_favor"`
23+
Frequency int `json:"frequency"`
24+
Progress int `json:"progress"`
25+
PathName string `json:"path_name"`
26+
}
27+
type Stat struct {
28+
QuestionID int `json:"question_id"`
29+
QuestionArticleLive bool `json:"question__article__live"`
30+
QuestionArticleSlug string `json:"question__article__slug"`
31+
QuestionTitle string `json:"question__title"`
32+
QuestionTitleSlup string `json:"question__title_slug"`
33+
QuestionHide bool `json:"question__hide"`
34+
TotalAcs int `json:"total_acs"`
35+
TotalSubmitted int `json:"total_submitted"`
36+
FrontendQuestionID int `json:"frontend_question_id"`
37+
IsNewQuestion bool `json:"is_new_question"`
38+
}
39+
40+
type Difficulty struct {
41+
Level int `json:"level"`
42+
}
43+
44+
func GetAllleetcodeInstance() {
45+
46+
}

cmd/leetcode/problem.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,30 @@ func formatId(id int) string {
148148
// 格式化提名称
149149
func formatName(name string) string {
150150
str := ""
151-
for _, v := range name {
151+
for i, v := range name {
152152
if v == ' ' {
153153
str = str + "-"
154154
continue
155155
}
156-
if v == '(' || v == ')' {
156+
if v == '(' {
157+
str = str + "-"
158+
continue
159+
}
160+
161+
if v == ')' {
162+
continue
163+
}
164+
if v == ',' {
165+
continue
166+
}
167+
if i > 0 && name[i-1] == '-' {
168+
str = str + string(v)
157169
continue
158170
}
159171
str = str + string(v)
160172
}
173+
if name[len(name)-1:] == "-" {
174+
name = name[:len(name)-1]
175+
}
161176
return str
162177
}

cmd/leetcode/summary.go

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package leetcode
22

33
import (
44
"bytes"
5+
"fmt"
56
"html/template"
67
"io/ioutil"
78
"log"
@@ -22,6 +23,7 @@ type TodoPageData struct {
2223

2324
// Auto make the Gitbook SUMMARY
2425
func MakeGitbookSummary(problems []Problem) {
26+
problems = CheckProblemExists(problems)
2527

2628
file, err := os.OpenFile(SOURCE_SOLUTION_SUMMARY_FILE_PATH, os.O_RDONLY, 0600)
2729
defer file.Close()
@@ -40,6 +42,19 @@ func MakeGitbookSummary(problems []Problem) {
4042
err = tmpl.Execute(&tmpRes, problems)
4143
write("SUMMARY.md", string(tmpRes.Bytes()))
4244
}
45+
func CheckProblemExists(problems []Problem) []Problem {
46+
tmp := []Problem{}
47+
48+
for i := 0; i < len(problems); i++ {
49+
isExist, _ := PathExists("src/" + problems[i].PathName)
50+
if isExist {
51+
tmp = append(tmp, problems[i])
52+
} else {
53+
fmt.Println(problems[i].PathName)
54+
}
55+
}
56+
return tmp
57+
}
4358

4459
func write(path, content string) {
4560
err := ioutil.WriteFile(path, []byte(content), 0755)

cmd/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66

77
func main() {
88
problems := leetcode.GetSotedproblemsInstance()
9+
//problems := leetcode.GetProblemsJosn()
910

1011
//for _, v := range problems {
12+
// fmt.Println(v.Stat.QuestionID)
13+
// fmt.Println(v.Stat.QuestionTitle)
1114
// fmt.Println(v.PathName)
1215
//}
1316

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)