#!/bin/bash ## ## Court case information behind one set of actions. A provider per court system: ## va Virginia General District Court, https://eapps.courts.state.va.us/gdcourts/ ## cl federal courts via CourtListener, https://www.courtlistener.com/help/api/ ## CMD=$(basename $0) TMP=$HOME/.tmp/$CMD ; mkdir -p $TMP TENTEN_DIR=$(dirname "$(dirname "$(realpath "$0")")") LIBEXEC=$TENTEN_DIR/libexec/$CMD S3_CACHE=s3://archive-benjisimon-com/cache/$CMD usage() { echo "Usage: $CMD -a courts [-R] [-v] # id|name|level|jurisdiction" echo "Usage: $CMD -a search -c court -l last [-f first] [-V] [-H] [-v] # va: case|name|hearing_date|hearing_time|charge|note" echo "Usage: $CMD -a search -q keywords [-c court] [-v] # cl: docket|case_name|court|docket_number|date_filed|date_terminated" echo "Usage: $CMD -a case -c court -i case [-l last [-f first]] [-V] [-v] # section|label|value" echo "Usage: $CMD -a events -c court -i case [-l last [-f first]] [-V] [-e N] [-v] # va: event|date|time|result|type|courtroom|plea|continuance" echo " # cl: event|number|date|description|documents" echo "Usage: $CMD -a documents -c court -i docket [-e N] [-v] # document|entry|attachment|pages|description" echo "Usage: $CMD -a document -c court -i docket -e N # plain text of that docket entry's documents" echo "Usage: $CMD -a custody -c county -l last [-f first] [-v] # inmate|label|value, booking|label|value, bond|type|amount, court|date|court," echo " # charge|description|offense_date|docket|disposition|disposition_date|sentence" echo "" echo " -c provider-qualified court id from the courts action (va:013, cl:dcd); va also takes a name" echo " fragment (va:arlington). For custody, a county with a reader in libexec/$CMD/jail/ (va:arlington)" echo " -i case number as search prints it (va: GC26000000-00; cl: docket id)" echo " -l/-f last and first name; the va case and events actions need the name that found the case" echo " -q keywords or case name (cl)" echo " -e docket entry number (cl)" echo " -H include archived cases (va; default: current only)" echo " -V civil cases (va; default: traffic/criminal)" echo " -R refetch instead of using the cache (court list and cl lookups; cl documents are kept indefinitely, other cl lookups an hour)" echo " -v raw JSON instead of |-delimited output" echo " custody lists only people in custody right now: no output means not held there today;" echo " actions a provider has nothing for say so" exit 1 } unset ACTION COURT LAST FIRST CASE ARCHIVED CIVIL VERBOSE QUERY ENTRY REFRESH while getopts ":a:c:l:f:i:q:e:HVRvh" o; do case "$o" in a) ACTION=$OPTARG ;; c) COURT=$OPTARG ;; l) LAST=$OPTARG ;; f) FIRST=$OPTARG ;; i) CASE=$OPTARG ;; q) QUERY=$OPTARG ;; e) ENTRY=$OPTARG ;; H) ARCHIVED=--archived ;; V) CIVIL=V ;; R) REFRESH=--refresh ;; v) VERBOSE=--verbose ;; *|h) usage ;; esac done ## Provider named by the court id's prefix; an unprefixed id belongs to va. PROVIDER=va ; COURT_ID=$COURT case "$COURT" in *:*) PROVIDER=${COURT%%:*} ; COURT_ID=${COURT#*:} ;; esac ## Runs the va PHP client with a throwaway cookie jar; remaining args are its options. va_site() { local jar jar=$(mktemp $TMP/jar.XXXXXX) php "$LIBEXEC/va.php" --jar "$jar" --division "${CIVIL:-T}" $VERBOSE "$@" local status=$? rm -f "$jar" return $status } ## Runs the CourtListener PHP client; remaining args are its options. cl_site() { local token token=$(opassist -a password -p iiifff -n "Court Listener API Key") || exit 1 mkdir -p $TMP/cache cache_pull php "$LIBEXEC/cl.php" --token "$token" --cache "$TMP/cache" $REFRESH $VERBOSE "$@" local status=$? cache_push return $status } ## The court list is shared across machines through S3. cache_pull() { aws --profile=i2x s3 sync --quiet $S3_CACHE $TMP/cache || echo "Warning: couldn't pull $S3_CACHE; using the local cache" >&2 } cache_push() { aws --profile=i2x s3 sync --quiet $TMP/cache $S3_CACHE || echo "Warning: couldn't push $TMP/cache to $S3_CACHE" >&2 } need() { for value in "$@"; do [ -z "$value" ] && usage; done } unsupported() { echo "$PROVIDER has no $ACTION" >&2 exit 0 } case "$ACTION" in courts) va_site --action courts cl_site --action courts ;; search) [ -z "$COURT" ] && [ -n "$QUERY" ] && PROVIDER=cl case "$PROVIDER" in va) need "$COURT" "$LAST" va_site --action search --court "$COURT_ID" --last "$LAST" --first "${FIRST:-}" $ARCHIVED ;; cl) need "$QUERY" cl_site --action search --query "$QUERY" ${COURT:+--court "$COURT_ID"} ;; *) usage ;; esac ;; case|events) need "$COURT" "$CASE" case "$PROVIDER" in va) need "$LAST" va_site --action "$ACTION" --court "$COURT_ID" --last "$LAST" --first "${FIRST:-}" --case "$CASE" ;; cl) cl_site --action "$ACTION" --docket "$CASE" ${ENTRY:+--entry "$ENTRY"} ;; *) usage ;; esac ;; documents|document) need "$COURT" "$CASE" case "$PROVIDER" in va) unsupported ;; cl) cl_site --action "$ACTION" --docket "$CASE" ${ENTRY:+--entry "$ENTRY"} ;; *) usage ;; esac ;; custody) need "$COURT" "$LAST" [ "$PROVIDER" = va ] || unsupported county=$(echo "$COURT_ID" | tr 'A-Z' 'a-z') reader="$LIBEXEC/jail/$county.php" if [ ! -f "$reader" ]; then echo "No custody lookup for $county; available: $(ls "$LIBEXEC/jail" | sed 's/\.php$//' | paste -sd' ' -)" >&2 exit 1 fi php "$reader" --last "$LAST" --first "${FIRST:-}" $VERBOSE ;; *) usage ;; esac