@@ -9,18 +9,6 @@ import (
99 "github.com/openset/leetcode/internal/client"
1010)
1111
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-
2412// ProblemsType - leetcode.ProblemsType
2513type ProblemsType struct {
2614 UserName string `json:"user_name"`
@@ -46,6 +34,17 @@ type StatStatusPairsType struct {
4634 Progress int `json:"progress"`
4735}
4836
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+
4948type statType struct {
5049 QuestionID int `json:"question_id"`
5150 QuestionArticleLive bool `json:"question__article__live"`
@@ -59,28 +58,8 @@ type statType struct {
5958 IsNewQuestion bool `json:"is_new_question"`
6059}
6160
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 )
8463}
8564
8665func (s * statType ) QuestionTitleSnake () string {
@@ -95,8 +74,8 @@ func (s *statType) TranslationTitle() string {
9574 return title
9675}
9776
98- func ( s * statType ) Lang () string {
99- return getLang ( s . QuestionTitleSlug )
77+ type difficultyType struct {
78+ Level int `json:"level"`
10079}
10180
10281func (d * difficultyType ) LevelName () string {
@@ -107,3 +86,24 @@ func (d *difficultyType) LevelName() string {
10786 }
10887 return m [d .Level ]
10988}
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