gameini-ratings-from-wiki.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #! /bin/bash
  2. if [ "$#" -ne 1 ]; then
  3. echo >&2 "usage: $0 <gameini-file>"
  4. exit 1
  5. fi
  6. [ -z "$PGPASSWORD" ] && read -rs -p 'Enter PostgreSQL password: ' PGPASSWORD
  7. export PGHOST=postgresql1.alwaysdata.com
  8. export PGDATABASE=dolphin-emu_wiki
  9. export PGUSER=dolphin-emu_wiki
  10. export PGPASSWORD
  11. sql() {
  12. psql -A -t -F ',' -c "$1"
  13. }
  14. GAME_ID=$(basename "$1" | cut -c -6)
  15. if ! echo "$GAME_ID" | grep -q '[A-Z0-9]\{6\}'; then
  16. echo >&2 "Invalid game ID: $GAME_ID"
  17. exit 1
  18. fi
  19. GAME_ID_GLOB=$(echo "$GAME_ID" | sed 's/\(...\).\(..\)/\1_\2/')
  20. RATING=$(sql "
  21. SELECT
  22. rating_content.old_text
  23. FROM
  24. page gid_page
  25. LEFT JOIN pagelinks gid_to_main
  26. ON gid_to_main.pl_from = gid_page.page_id
  27. LEFT JOIN page rating_page
  28. ON rating_page.page_title = ('Ratings/' || gid_to_main.pl_title)
  29. LEFT JOIN revision rating_rev
  30. ON rating_rev.rev_id = rating_page.page_latest
  31. LEFT JOIN pagecontent rating_content
  32. ON rating_content.old_id = rating_rev.rev_text_id
  33. WHERE
  34. gid_page.page_title LIKE '$GAME_ID_GLOB'
  35. LIMIT 1
  36. " | grep '^[1-5]$')
  37. if ! [ -z "$RATING" ]; then
  38. sed -i "s/^EmulationStateId.*$/EmulationStateId = $RATING/" "$1"
  39. fi