Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 908a49d

Browse files
author
Sandy
authored
Merge pull request #24 from openset/develop
Add: QuestionData
2 parents 15dfca6 + 3aa0729 commit 908a49d

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

‎internal/leetcode/question_data.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package leetcode
2+
3+
import (
4+
"io/ioutil"
5+
"net/http"
6+
"strings"
7+
"encoding/json"
8+
)
9+
10+
func QuestionData(titleSlug string) (qd QuestionDataType) {
11+
jsonStr := `{
12+
"operationName": "questionData",
13+
"variables": {
14+
"titleSlug": "` + titleSlug + `"
15+
},
16+
"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"
17+
}`
18+
resp, err := http.Post(GraphqlUrl, "application/json", strings.NewReader(jsonStr))
19+
checkErr(err)
20+
defer resp.Body.Close()
21+
body, err := ioutil.ReadAll(resp.Body)
22+
checkErr(err)
23+
err = json.Unmarshal(body, &qd)
24+
checkErr(err)
25+
return
26+
}
27+
28+
type QuestionDataType struct {
29+
Errors []errorType `json:"errors"`
30+
Data dataType `json:"data"`
31+
}
32+
33+
type errorType struct {
34+
Message string `json:"message"`
35+
}
36+
37+
type dataType struct {
38+
Question questionType `json:"question"`
39+
}
40+
41+
type questionType struct {
42+
QuestionId string `json:"questionId"`
43+
QuestionFrontendId string `json:"questionFrontendId"`
44+
BoundTopicId string `json:"boundTopicId"`
45+
Title string `json:"title"`
46+
TitleSlug string `json:"titleSlug"`
47+
Content string `json:"content"`
48+
TranslatedTitle string `json:"translatedTitle"`
49+
TranslatedContent string `json:"translatedContent"`
50+
IsPaidOnly bool `json:"isPaidOnly"`
51+
Difficulty string `json:"difficulty"`
52+
Likes int `json:"likes"`
53+
Dislikes int `json:"dislikes"`
54+
IsLiked int `json:"isLiked"`
55+
SimilarQuestions string `json:"similarQuestions"`
56+
CodeSnippets []codeSnippetsType `json:"codeSnippets"`
57+
}
58+
59+
type codeSnippetsType struct {
60+
Lang string `json:"lang"`
61+
LangSlug string `json:"langSlug"`
62+
Code string `json:"code"`
63+
}
64+
65+
type SimilarQuestionType struct {
66+
Title string `json:"title"`
67+
TitleSlug string `json:"titleSlug"`
68+
Difficulty string `json:"difficulty"`
69+
TranslatedTitle string `json:"translatedTitle"`
70+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /