vimgolf
vimgolf copied to clipboard
List challenges from CLI
It would be convenient to be able to list (and search?) challenges from the CLI.
Maybe once the web interface is improved, it will not be that much of a problem.
Hi,
Basically you've got them from main page:
$ curl http://vimgolf.com/ | sed -ne '/challenges/p'
Listing challenges a user submitted would be great.
Sure, they can be picked out from the html. An API call would be nice though.
perhaps this will work nicely as a wrapper:
$ cat golf
#!/bin/bash
function golf {
local page shouldexit
page=1
shouldexit=0
while [ $shouldexit != 1 ]; do
curl -s http://www.vimgolf.com/?page=$page \
| grep challenges/ \
| sed 's#.*challenges/\(.*\)">\(.*\)<.*#\2 :: \1#' \
| awk 'BEGIN { FS = "::" }; { printf "%50s %s\n", $1, $2 }'
echo
echo "Action:"
echo "[N]ext, [P]revious, Page [N], [Q]uit, [challenge ID]"
while true; do
read -p '>> ' prompt
if [[ $prompt =~ [Nn] ]]; then
page=$((page + 1))
break
elif [[ $prompt =~ [Pp] ]]; then
page=$((page - 1))
break
elif [[ $prompt =~ [0-9] ]]; then
page=$prompt
break
elif [[ $prompt =~ [Qq] ]]; then
shouldexit=1
break
elif [[ $prompt =~ [a-z0-9]{24} ]]; then
shouldexit=1
echo starting vimgolf!!
vimgolf put "$prompt"
break
fi
done
done
}
golf
That s a good start : before upgrading the gem we can simply fetch it with bash.
It s easy to add a new route something like /api/challenges
And this route can return all the challenge (same data has homepage) without pagination. And a simple grep -i can do the search.
The question is : Which format is best suited for bash ? Csv ? Json ? Something custom ? I would say csv but any charactere can be present in the description
I’d say first things first, either adopt a custom separator or disallow special characters in the description (this might also prevent the risk of command injections in some custom implementations maybe?)