File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ source scripts/common.bash
4+ source scripts/leetcode_helper.bash
5+
6+ function main() {
7+ load_env_vars
8+
9+ # Check if required commands are installed
10+ check_command " jq"
11+ check_command " bash"
12+
13+ # Check if the problem title-slug or URL is provided
14+ if [ " $# " -eq 1 ]; then
15+ input=" $1 "
16+ if [[ " $input " == * " https://leetcode.com/problems/" * ]]; then
17+ # If the input is a LeetCode URL
18+ problem_slug=$( extract_problem_name " $input " )
19+ else
20+ # If the input is already a title-slug
21+ problem_slug=" $input "
22+ fi
23+ else
24+ echo " Please provide the LeetCode problem title-slug or URL."
25+ exit 1
26+ fi
27+
28+ echo " Problem Slug: $problem_slug "
29+
30+ # GraphQL query to fetch problem details
31+ query=$( make_query " $problem_slug " )
32+
33+ echo " Requesting problem details from LeetCode GraphQL API..."
34+
35+ # Send a POST request to the LeetCode GraphQL API
36+ response=$( request " $query " )
37+
38+ # Check if the response contains valid data
39+ if ! echo -E " $response " | jq -e ' .data.question' > /dev/null 2>&1 ; then
40+ echo -E " $response "
41+ echo " Failed to receive a valid response from the LeetCode API. Exiting the script."
42+ exit 1
43+ fi
44+
45+ echo " Received problem details response from LeetCode."
46+
47+ # Create the file
48+
49+ create_file " $response "
50+ }
51+
52+ # Call the main function
53+ main " $@ "
You can’t perform that action at this time.
0 commit comments