@@ -11,10 +11,10 @@ function get_question_slug()
11
11
QUESTION_TITLE_SLUG=$( echo $QUESTION_TITLE_SLUG | sed ' s/\/.*//g' ) # remove the needless url path
12
12
}
13
13
14
- function query_problem_xidel()
14
+ function query_problem_xidel()
15
15
{
16
16
# xidel change the -q option to -s after 0.9.4 version, so we have to check that
17
- # if xidel has -q option, then it will return error.
17
+ # if xidel has -q option, then it will return error.
18
18
19
19
OPT=
20
20
@@ -23,12 +23,12 @@ function query_problem_xidel()
23
23
if [ $? -ne 0 ]; then
24
24
OPT=-q
25
25
else
26
- # if xidel has -s option, then it will return error.
26
+ # if xidel has -s option, then it will return error.
27
27
xidel -s 2> /dev/null
28
28
if [ $? -ne 0 ]; then
29
29
OPT=-s
30
30
fi
31
- fi
31
+ fi
32
32
set -e
33
33
34
34
QUESTION_CONTENT=$( xidel ${OPT} ${TMP_JSON_FILE} -e ' $json("data").question.content' | sed -e ' s/<[^>]*>//g; s/ / /g; s/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'/\' " '" ' /g; s/“/\"/g;' )
@@ -41,10 +41,10 @@ function query_problem_xidel()
41
41
42
42
QUESTION_FRONTEND_ID=$( xidel ${OPT} ${TMP_JSON_FILE} -e ' $json("data").question.questionFrontendId' )
43
43
44
- # QUESTION_CATEGORY=$(xidel ${OPT} ${TMP_JSON_FILE} -e '$json("data").question.categoryTitle')
44
+ # QUESTION_CATEGORY=$(xidel ${OPT} ${TMP_JSON_FILE} -e '$json("data").question.categoryTitle')
45
45
}
46
46
47
- function query_problem_jq()
47
+ function query_problem_jq()
48
48
{
49
49
QUESTION_CONTENT=$( jq -r ' .data.question.content' ${TMP_JSON_FILE} | sed -e ' s/<sup>/\^/g' | sed -e ' s/<[^>]*>//g; s/ / /g; s/&/\&/g; s/</\</g; s/>/\>/g; s/"/\"/g; s/'/\' " '" ' /g; s/“/\"/g;' )
50
50
@@ -55,17 +55,17 @@ function query_problem_jq()
55
55
QUESTION_ID=$( jq -r ' .data.question.questionId' ${TMP_JSON_FILE} )
56
56
57
57
QUESTION_FRONTEND_ID=$( jq -r ' .data.question.questionFrontendId' ${TMP_JSON_FILE} )
58
-
58
+
59
59
}
60
60
61
61
function query_problem()
62
62
{
63
63
TMP_JSON_FILE=tmp.json
64
64
65
- # curl -s "https://leetcode.com/graphql?query=query%20getQuestionDetail(%24titleSlug%3A%20String!)%20%7B%0A%20%20isCurrentUserAuthenticated%0A%20%20question(titleSlug%3A%20%24titleSlug)%20%7B%0A%20%20%20%20questionId%0A%20%20%20%20questionFrontendId%0A%20%20%20%20questionTitle%0A%20%20%20%20translatedTitle%0A%20%20%20%20questionTitleSlug%0A%20%20%20%20content%0A%20%20%20%20translatedContent%0A%20%20%20%20difficulty%0A%20%20%20%20stats%0A%20%20%20%20contributors%0A%20%20%20%20similarQuestions%0A%20%20%20%20discussUrl%0A%20%20%20%20mysqlSchemas%0A%20%20%20%20randomQuestionUrl%0A%20%20%20%20sessionId%0A%20%20%20%20categoryTitle%0A%20%20%20%20submitUrl%0A%20%20%20%20interpretUrl%0A%20%20%20%20codeDefinition%0A%20%20%20%20sampleTestCase%0A%20%20%20%20enableTestMode%0A%20%20%20%20metaData%0A%20%20%20%20enableRunCode%0A%20%20%20%20enableSubmit%0A%20%20%20%20judgerAvailable%0A%20%20%20%20infoVerified%0A%20%20%20%20envInfo%0A%20%20%20%20urlManager%0A%20%20%20%20article%0A%20%20%20%20questionDetailUrl%0A%20%20%20%20discussCategoryId%0A%20%20%20%20discussSolutionCategoryId%0A%20%20%20%20libraryUrl%0A%20%20%20%20companyTags%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%20%20translatedName%0A%20%20%20%20%7D%0A%20%20%20%20topicTags%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%20%20translatedName%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20interviewed%20%7B%0A%20%20%20%20interviewedUrl%0A%20%20%20%20companies%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%7D%0A%20%20%20%20timeOptions%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%20%20stageOptions%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20subscribeUrl%0A%20%20isPremium%0A%20%20loginUrl%0A%7D%0A&operationName=getQuestionDetail&variables=%7B%22titleSlug%22%3A%22${2}%22%7D" > ${TMP_JSON_FILE}
65
+ # curl -s "https://leetcode.com/graphql?query=query%20getQuestionDetail(%24titleSlug%3A%20String!)%20%7B%0A%20%20isCurrentUserAuthenticated%0A%20%20question(titleSlug%3A%20%24titleSlug)%20%7B%0A%20%20%20%20questionId%0A%20%20%20%20questionFrontendId%0A%20%20%20%20questionTitle%0A%20%20%20%20translatedTitle%0A%20%20%20%20questionTitleSlug%0A%20%20%20%20content%0A%20%20%20%20translatedContent%0A%20%20%20%20difficulty%0A%20%20%20%20stats%0A%20%20%20%20contributors%0A%20%20%20%20similarQuestions%0A%20%20%20%20discussUrl%0A%20%20%20%20mysqlSchemas%0A%20%20%20%20randomQuestionUrl%0A%20%20%20%20sessionId%0A%20%20%20%20categoryTitle%0A%20%20%20%20submitUrl%0A%20%20%20%20interpretUrl%0A%20%20%20%20codeDefinition%0A%20%20%20%20sampleTestCase%0A%20%20%20%20enableTestMode%0A%20%20%20%20metaData%0A%20%20%20%20enableRunCode%0A%20%20%20%20enableSubmit%0A%20%20%20%20judgerAvailable%0A%20%20%20%20infoVerified%0A%20%20%20%20envInfo%0A%20%20%20%20urlManager%0A%20%20%20%20article%0A%20%20%20%20questionDetailUrl%0A%20%20%20%20discussCategoryId%0A%20%20%20%20discussSolutionCategoryId%0A%20%20%20%20libraryUrl%0A%20%20%20%20companyTags%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%20%20translatedName%0A%20%20%20%20%7D%0A%20%20%20%20topicTags%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%20%20translatedName%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20interviewed%20%7B%0A%20%20%20%20interviewedUrl%0A%20%20%20%20companies%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%20%20slug%0A%20%20%20%20%7D%0A%20%20%20%20timeOptions%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%20%20stageOptions%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20subscribeUrl%0A%20%20isPremium%0A%20%20loginUrl%0A%7D%0A&operationName=getQuestionDetail&variables=%7B%22titleSlug%22%3A%22${2}%22%7D" > ${TMP_JSON_FILE}
66
66
67
67
#
68
- # NOTE: leetcode server supports `br` encoding and make it high priority. But curl doesn't support it,
68
+ # NOTE: leetcode server supports `br` encoding and make it high priority. But curl doesn't support it,
69
69
# So, you need make sure the `accept-encoding` hasn't br in the request header.
70
70
# (if you copy & paste the curl script from Chrome, the `br` could be added!)
71
71
#
@@ -100,7 +100,7 @@ function detect_os()
100
100
echo ${platform}
101
101
}
102
102
103
- function install_brew()
103
+ function install_brew()
104
104
{
105
105
TRUE_CMD=` which true`
106
106
brew=` type -P brew || ${TRUE_CMD} `
@@ -115,10 +115,10 @@ function manually_install_jq() {
115
115
echo " Unknown platform, please install 'jq' manually!"
116
116
echo " Dowload Site: https://stedolan.github.io/jq/download/"
117
117
}
118
- function install_jq()
118
+ function install_jq()
119
119
{
120
120
echo " Install jq ..."
121
-
121
+
122
122
platform=` detect_os`
123
123
124
124
if [[ " $platform " == " unknown" ]]; then
@@ -139,7 +139,7 @@ function install_jq()
139
139
;;
140
140
CentOS* ) echo sudo yum install jq
141
141
;;
142
- * ) manually_install_jq
142
+ * ) manually_install_jq
143
143
exit 1;
144
144
esac
145
145
fi
0 commit comments