Script to find your unanswered discourse questions

I post a lot of questions here and get a lot of help.

Every once in a while, I like to go through my old unanswered posts and see if I can answer my own question (or if I’ve failed to mark a response as the answer), which I hope will help other learners find their way.

I was excited to find that one can append .json to many of the discourse URLs and get a json response, and further that the endpoint for a given user’s list of topics includes a has_accepted_answer attribute.

This made is really easy to whip up a quick script to scrape all my unanswered topics and spit out their urls (which I can then pipe to something like parallel open on my Mac).

Just thought I’d share! Should be able to use it as ./ MyUsername

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash --pure
#!nix-shell -p curl -p cacert
#!nix-shell -p jq

main() {
  local username=${1:-n8henrie}
  curl -s "${username}.json" |
    jq -r '.topic_list.topics[] | select(.has_accepted_answer | not) | "" + .slug'
main "$@"