Compare commits
2 commits
e4d398709b
...
33ad6302da
| Author | SHA1 | Date | |
|---|---|---|---|
| 33ad6302da | |||
| 33dbbc19e2 |
1 changed files with 16 additions and 4 deletions
20
create.sh
20
create.sh
|
|
@ -9,7 +9,6 @@ echo "$id" | grep -q "^[1-9][0-9]\{,4\}$" || {
|
||||||
|
|
||||||
parent=$((id / 100))
|
parent=$((id / 100))
|
||||||
pdir="solutions/${parent}/q${id}"
|
pdir="solutions/${parent}/q${id}"
|
||||||
|
|
||||||
sol_file="${pdir}/solution.go"
|
sol_file="${pdir}/solution.go"
|
||||||
|
|
||||||
if [ -f "$sol_file" ]; then
|
if [ -f "$sol_file" ]; then
|
||||||
|
|
@ -21,10 +20,23 @@ title_slug=$(jq -r "select(.id == $id) | .titleSlug" ./problemset.jsonl)
|
||||||
echo "Err: problem $id not found in the problem set." >&2
|
echo "Err: problem $id not found in the problem set." >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
problem_url="https://leetcode.com/problems/$title_slug/"
|
||||||
|
|
||||||
echo -e "Creating template for problem \033[32m${id}: $title_slug\033[0m" >&2
|
echo -e "Creating template for problem \033[32m${id}: $title_slug\033[0m" >&2
|
||||||
mkdir -pv "$pdir"
|
mkdir -pv "$pdir"
|
||||||
echo "// Package q$id implements solution for https://leetcode.com/problems/$title_slug/" > "$sol_file"
|
echo "// Package q$id implements a solution for $problem_url" > "$sol_file"
|
||||||
echo "package q$id" >> "$sol_file"
|
echo -e "package q$id\n" >> "$sol_file"
|
||||||
|
|
||||||
echo "Created $sol_file"
|
echo "Created: $sol_file"
|
||||||
|
|
||||||
|
echo "Fetching code snippet for Go ..."
|
||||||
|
curl -sSLf "${problem_url}description/" \
|
||||||
|
-H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8' \
|
||||||
|
-H 'accept-language: en-US,en;q=0.5' \
|
||||||
|
-H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36' \
|
||||||
|
| grep -o 'NEXT_DATA[^>]*>.*' \
|
||||||
|
| sed 's/^[^>]*>//;s/<\/script.*//' \
|
||||||
|
| jq -r '[ .props.pageProps.dehydratedState.queries[].state.data.question.codeSnippets | select( . != null) | .[] | select(.langSlug == "golang") ][0].code' \
|
||||||
|
>> "$sol_file"
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue