@@ -9,18 +9,6 @@ import (
9
9
"github.com/openset/leetcode/internal/client"
10
10
)
11
11
12
- // ProblemsAll - leetcode.ProblemsAll
13
- func ProblemsAll () (ps ProblemsType ) {
14
- data := remember (problemsAllFile , 2 , func () []byte {
15
- return client .Get (apiProblemsAllURL )
16
- })
17
- jsonDecode (data , & ps )
18
- sort .Slice (ps .StatStatusPairs , func (i , j int ) bool {
19
- return ps .StatStatusPairs [i ].Stat .FrontendQuestionID > ps .StatStatusPairs [j ].Stat .FrontendQuestionID
20
- })
21
- return
22
- }
23
-
24
12
// ProblemsType - leetcode.ProblemsType
25
13
type ProblemsType struct {
26
14
UserName string `json:"user_name"`
@@ -46,6 +34,17 @@ type StatStatusPairsType struct {
46
34
Progress int `json:"progress"`
47
35
}
48
36
37
+ // WriteRow - leetcode.WriteRow
38
+ func (problem * StatStatusPairsType ) WriteRow (buf * bytes.Buffer ) {
39
+ format := "| <span id=\" %d\" >%d</span> | [%s](https://leetcode.com/problems/%s%s)%s | [%s](https://github.com/openset/leetcode/tree/master/problems/%s) | %s |\n "
40
+ id := problem .Stat .FrontendQuestionID
41
+ stat := problem .Stat
42
+ title := strings .TrimSpace (problem .Stat .QuestionTitle )
43
+ titleSlug := stat .QuestionTitleSlug
44
+ levelName := problem .Difficulty .LevelName ()
45
+ buf .WriteString (fmt .Sprintf (format , id , id , title , titleSlug , stat .TranslationTitle (), problem .PaidOnly .Str (), stat .Lang (), titleSlug , levelName ))
46
+ }
47
+
49
48
type statType struct {
50
49
QuestionID int `json:"question_id"`
51
50
QuestionArticleLive bool `json:"question__article__live"`
@@ -59,28 +58,8 @@ type statType struct {
59
58
IsNewQuestion bool `json:"is_new_question"`
60
59
}
61
60
62
- type difficultyType struct {
63
- Level int `json:"level"`
64
- }
65
-
66
- type paidType bool
67
-
68
- // WriteRow - leetcode.WriteRow
69
- func (problem * StatStatusPairsType ) WriteRow (buf * bytes.Buffer ) {
70
- format := "| <span id=\" %d\" >%d</span> | [%s](https://leetcode.com/problems/%s%s)%s | [%s](https://github.com/openset/leetcode/tree/master/problems/%s) | %s |\n "
71
- id := problem .Stat .FrontendQuestionID
72
- stat := problem .Stat
73
- title := strings .TrimSpace (problem .Stat .QuestionTitle )
74
- titleSlug := stat .QuestionTitleSlug
75
- levelName := problem .Difficulty .LevelName ()
76
- buf .WriteString (fmt .Sprintf (format , id , id , title , titleSlug , stat .TranslationTitle (), problem .PaidOnly .Str (), stat .Lang (), titleSlug , levelName ))
77
- }
78
-
79
- func (p paidType ) Str () string {
80
- if p {
81
- return LockStr
82
- }
83
- return ""
61
+ func (s * statType ) Lang () string {
62
+ return getLang (s .QuestionTitleSlug )
84
63
}
85
64
86
65
func (s * statType ) QuestionTitleSnake () string {
@@ -95,8 +74,8 @@ func (s *statType) TranslationTitle() string {
95
74
return title
96
75
}
97
76
98
- func ( s * statType ) Lang () string {
99
- return getLang ( s . QuestionTitleSlug )
77
+ type difficultyType struct {
78
+ Level int `json:"level"`
100
79
}
101
80
102
81
func (d * difficultyType ) LevelName () string {
@@ -107,3 +86,24 @@ func (d *difficultyType) LevelName() string {
107
86
}
108
87
return m [d .Level ]
109
88
}
89
+
90
+ type paidType bool
91
+
92
+ func (p paidType ) Str () string {
93
+ if p {
94
+ return LockStr
95
+ }
96
+ return ""
97
+ }
98
+
99
+ // ProblemsAll - leetcode.ProblemsAll
100
+ func ProblemsAll () (ps ProblemsType ) {
101
+ data := remember (problemsAllFile , 2 , func () []byte {
102
+ return client .Get (apiProblemsAllURL )
103
+ })
104
+ jsonDecode (data , & ps )
105
+ sort .Slice (ps .StatStatusPairs , func (i , j int ) bool {
106
+ return ps .StatStatusPairs [i ].Stat .FrontendQuestionID > ps .StatStatusPairs [j ].Stat .FrontendQuestionID
107
+ })
108
+ return
109
+ }
0 commit comments