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

Appearance settings

Latest commit

ย 

History

History
History
executable file
ยท
67 lines (52 loc) ยท 1.83 KB

File metadata and controls

executable file
ยท
67 lines (52 loc) ยท 1.83 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
source scripts/common.bash
source scripts/leetcode_helper.bash
function main() {
load_env_vars
# Check if required commands are installed
check_command "jq"
check_command "bash"
check_command "brew"
# Set the required Bash version
local required_bash_version="4.0.0"
# Check Bash version and proceed with installation if necessary
if check_bash_version "$required_bash_version"; then
echo "Bash version meets the minimum requirement (>= $required_bash_version). Skipping installation."
else
echo "Bash version does not meet the minimum requirement (>= $required_bash_version). Proceeding with installation using Homebrew..."
# Add your Homebrew installation commands here
brew update
brew install bash
fi
# Check if the problem title-slug or URL is provided
if [ "$#" -eq 1 ]; then
input="$1"
if [[ "$input" == *"https://leetcode.com/problems/"* ]]; then
# If the input is a LeetCode URL
problem_slug=$(extract_problem_name "$input")
else
# If the input is already a title-slug
problem_slug="$input"
fi
else
echo "Please provide the LeetCode problem title-slug or URL."
exit 1
fi
echo "Problem Slug: $problem_slug"
# GraphQL query to fetch problem details
query=$(make_query "$problem_slug")
echo "Requesting problem details from LeetCode GraphQL API..."
# Send a POST request to the LeetCode GraphQL API
response=$(request "$query")
# Check if the response contains valid data
if ! echo -E "$response" | jq -e '.data.question' >/dev/null 2>&1; then
echo -E "$response"
echo "Failed to receive a valid response from the LeetCode API. Exiting the script."
exit 1
fi
echo "Received problem details response from LeetCode."
# Create the file
create_file "$response"
}
# Call the main function
main "$@"
Morty Proxy This is a proxified and sanitized view of the page, visit original site.