-
Notifications
You must be signed in to change notification settings - Fork 0
/
leetcode.bash
executable file
·53 lines (40 loc) · 1.29 KB
/
leetcode.bash
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
#!/usr/bin/env bash
source scripts/common.bash
source scripts/leetcode_helper.bash
function main() {
# Check if required commands are installed
check_command "jq"
# 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 "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 Swift file
create_swift_file "$response"
echo "Opening Xcode project..."
open_xcode_project
}
load_env_vars
# Call the main function
main "$@"