Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/leetcode/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/user"
"path"
"strings"
"time"

"github.com/openset/leetcode/internal/base"
Expand Down Expand Up @@ -112,3 +113,7 @@ func getCredential() (data url.Values) {
jsonDecode(cts, &data)
return
}

func slugToSnake(slug string) string {
return strings.Replace(slug, "-", "_", -1)
}
2 changes: 2 additions & 0 deletions internal/leetcode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
problemsDatabaseFile = "problems_database.json"
problemsShellFile = "problems_shell.json"
questionTranslationFile = "question_translation.json"
questionDataFile = "question_data_%s.json"
questionArticleFile = "question_article_%s.html"
topicTagFile = "topic_tag_%s.json"
tagsFile = "tag/tags.json"
)
3 changes: 1 addition & 2 deletions internal/leetcode/problems_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package leetcode
import (
"fmt"
"sort"
"strings"

"github.com/openset/leetcode/internal/client"
)
Expand Down Expand Up @@ -69,7 +68,7 @@ func (p paidType) Str() string {
}

func (s statType) QuestionTitleSnake() string {
return strings.Replace(s.QuestionTitleSlug, "-", "_", -1)
return slugToSnake(s.QuestionTitleSlug)
}

func (s statType) TranslationTitle() string {
Expand Down
3 changes: 1 addition & 2 deletions internal/leetcode/question_article.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"bytes"
"fmt"
"regexp"
"strings"

"github.com/openset/leetcode/internal/client"
)

func GetDescription(articleSlug string) string {
fmt.Println("\tquestion article", "saving...")
filename := fmt.Sprintf(questionArticleFile, strings.Replace(articleSlug, "-", "_", -1))
filename := fmt.Sprintf(questionArticleFile, slugToSnake(articleSlug))
html := remember(filename, 30, func() []byte {
return client.Get(fmt.Sprintf(questionArticleUrl, articleSlug))
})
Expand Down
4 changes: 2 additions & 2 deletions internal/leetcode/question_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func QuestionData(titleSlug string) (qd questionDataType) {
},
"query": "query questionData($titleSlug: String!) {\n question(titleSlug: $titleSlug) {\n questionId\n questionFrontendId\n boundTopicId\n title\n titleSlug\n content\n translatedTitle\n translatedContent\n isPaidOnly\n difficulty\n likes\n dislikes\n isLiked\n similarQuestions\n contributors {\n username\n profileUrl\n avatarUrl\n __typename\n }\n langToValidPlayground\n topicTags {\n name\n slug\n translatedName\n __typename\n }\n companyTagStats\n codeSnippets {\n lang\n langSlug\n code\n __typename\n }\n stats\n hints\n solution {\n id\n canSeeDetail\n __typename\n }\n status\n sampleTestCase\n metaData\n judgerAvailable\n judgeType\n mysqlSchemas\n enableRunCode\n enableTestMode\n envInfo\n __typename\n }\n}\n"
}`
filename := "question_data_" + strings.Replace(titleSlug, "-", "_", -1) + ".json"
filename := fmt.Sprintf(questionDataFile, slugToSnake(titleSlug))
graphQLRequest(filename, 30, jsonStr, &qd)
if qd.Data.Question.TitleSlug == "" {
os.Remove(getCachePath(filename))
Expand Down Expand Up @@ -177,7 +177,7 @@ func (question questionType) getFilePath(filename string) string {
}

func (question questionType) TitleSnake() string {
return strings.Replace(question.TitleSlug, "-", "_", -1)
return slugToSnake(question.TitleSlug)
}

func (question questionType) PackageName() string {
Expand Down
3 changes: 1 addition & 2 deletions internal/leetcode/tag.go → internal/leetcode/topic_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"regexp"
"sort"
"strconv"
"strings"

"github.com/openset/leetcode/internal/client"
)
Expand Down Expand Up @@ -68,7 +67,7 @@ func GetTopicTag(slug string) (tt topicTagType) {
},
"query": "query getTopicTag($slug: String!) {\n topicTag(slug: $slug) {\n name\n translatedName\n questions {\n status\n questionId\n questionFrontendId\n title\n titleSlug\n translatedTitle\n stats\n difficulty\n isPaidOnly\n topicTags {\n name\n translatedName\n slug\n __typename\n }\n companyTags {\n name\n translatedName\n slug\n __typename\n }\n __typename\n }\n frequencies\n __typename\n }\n favoritesLists {\n publicFavorites {\n ...favoriteFields\n __typename\n }\n privateFavorites {\n ...favoriteFields\n __typename\n }\n __typename\n }\n}\n\nfragment favoriteFields on FavoriteNode {\n idHash\n id\n name\n isPublicFavorite\n viewCount\n creator\n isWatched\n questions {\n questionId\n title\n titleSlug\n __typename\n }\n __typename\n}\n"
}`
filename := "topic_tag_" + strings.Replace(slug, "-", "_", -1) + ".json"
filename := fmt.Sprintf(topicTagFile, slugToSnake(slug))
graphQLRequest(filename, 3, jsonStr, &tt)
return
}
Expand Down