wfs_describeStoredQueries 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. usage() {
  3. [ -n "$*" ] && echo "$*"
  4. cat <<EOF
  5. $me [-d int] [keyword] [keyword]...
  6. Get stored queries descriptions from
  7. $URL
  8. -d int Level of detail:
  9. 0 - id only
  10. 1 - title & id on single line (default)
  11. 2 - title, id, description
  12. 3 - title, id, description, parameters with description
  13. Provide additional command line parameters to filter IDs by simple keywords.
  14. Example to get all location-based land forecast alternatives with medium detail:
  15. $me -d 2 :forecast: :point: :surface:
  16. EOF
  17. exit 1
  18. }
  19. URL="https://opendata.fmi.fi/wfs?service=WFS&version=2.0.0&request=describeStoredQueries"
  20. detail=1
  21. while getopts "d:h" opt; do
  22. case $opt in
  23. d) [[ "$OPTARG" =~ [0-3] ]] || usage "Option -${opt}: invalid number $OPTARG"
  24. detail="$OPTARG"
  25. ;;
  26. *) usage
  27. ;;
  28. esac
  29. done
  30. shift $((OPTIND-1))
  31. contains="contains(@id,':')"
  32. if [ -n "$*" ]; then
  33. for i in "$@"; do
  34. contains="$contains and contains(@id,'$i')"
  35. done
  36. fi
  37. data="$(curl -s "$URL")"
  38. case $detail in
  39. 0)
  40. xmlstarlet sel -N n="http://www.opengis.net/wfs/2.0" -t -m "/n:DescribeStoredQueriesResponse/n:StoredQueryDescription[$contains]" \
  41. -v "@id" -n <<<"$data"
  42. ;;
  43. 1)
  44. xmlstarlet sel -N n="http://www.opengis.net/wfs/2.0" -t -m "/n:DescribeStoredQueriesResponse/n:StoredQueryDescription[$contains]" \
  45. -v "n:Title" -o ' (' -v "@id" -o ')' -n <<<"$data"
  46. ;;
  47. 2)
  48. xmlstarlet sel -N n="http://www.opengis.net/wfs/2.0" -t -m "/n:DescribeStoredQueriesResponse/n:StoredQueryDescription[$contains]" \
  49. -v "n:Title" -o ' (' -v "@id" -o ')' -n -v "normalize-space(n:Abstract)" -n -n <<<"$data"
  50. ;;
  51. 3)
  52. xmlstarlet sel -N n="http://www.opengis.net/wfs/2.0" -t -m "/n:DescribeStoredQueriesResponse/n:StoredQueryDescription[$contains]" \
  53. -v "n:Title" -o ' (' -v "@id" -o ')' -n -v "normalize-space(n:Abstract)" -n -m "n:Parameter" -o ' ' -v "@name" -o ': ' -v "normalize-space(n:Abstract)" -n -b -n <<<"$data"
  54. ;;
  55. esac