WikiRando 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. #
  3. #############################################
  4. # --- WikiRando.sh --- #
  5. # #
  6. # Get random subject from English Wikipedia #
  7. # #
  8. #############################################
  9. # Logic behind this is as follows:-
  10. #
  11. # 1. Grab a random page from wikipedia using wget, and keep output quiet - save as temp file
  12. # 2. Pipe the resulting html into grep, only looking for the line that containers the page <title> - equivalent to subject
  13. # 3. Strip the opening html tag using cut
  14. # 4. Reverse the string from that line
  15. # 5. Remove the closing title tag, and the " - Wikipedia" portion of thepage title
  16. # 6. Reverse the string back to normal orientation, to keep it human-readable, and output to stdout
  17. # 7. Remove temp file
  18. wget -O temp.html -q https://en.wikipedia.org/wiki/Special:Random
  19. cat temp.html | grep "<title>" | cut -c 8- | rev | cut -c 21- | rev
  20. rm temp.html
  21. # Although this is just a simple script and could be incorporated into any script, I can
  22. # forsee a few use-cases where getting a random subject from Wikipedia to be useful.
  23. # And, ya know, UNIX philosphy - do one thing and do it well
  24. # This is part of my web-use "Chaffer" - props to Cory Doctorow's book homeland for the impetus