From d57324a26c3810cadb73ea20d3c2d07ed572de2b Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Wed, 10 Nov 2021 09:51:10 +0000 Subject: [PATCH] Add --where for arbitrary conditions --- wpull2-requeue | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wpull2-requeue b/wpull2-requeue index 5cd7bc0..9032481 100755 --- a/wpull2-requeue +++ b/wpull2-requeue @@ -1,11 +1,13 @@ #!/bin/bash -# Usage: wpull2-requeue [ACTION] [FILENAME] URLPATTERN +# Usage: wpull2-requeue [ACTION] [FILENAME] [--where] URLPATTERN_OR_WHERE # ACTION can be 'count' (default), 'print', or 'write' # FILENAME defaults to 'wpull.db' +# URLPATTERN_OR_WHERE is URLPATTERN if --where isn't used or WHERE if it is. # URLPATTERN uses SQLite's LIKE syntax with ESCAPE "\", i.e. % matches any number of characters, _ matches exactly one character, and a backslash can be used to escape these special characters. # Must not contain quotes. +# WHERE is an arbitrary SQLite 'WHERE' condition. The available tables are 'queued_urls' and 'url_strings', already joined together. -if [[ $# -eq 3 || ( $# -eq 2 && ( "$1" == 'count' || "$1" == 'print' || "$1" == 'write' )) ]] +if [[ $# -eq 4 || ( $# -ge 2 && $# -le 3 && ( "$1" == 'count' || "$1" == 'print' || "$1" == 'write' )) ]] then action="$1" shift @@ -13,7 +15,7 @@ else action=count fi -if [[ $# -eq 2 ]] +if [[ $# -eq 3 || ( $# -eq 2 && "$1" != '--where' ) ]] then filename="$1" shift @@ -26,9 +28,21 @@ then exit 1 fi -urlpattern="$1" +where= +if [[ "$1" == '--where' ]] +then + where=1 + shift +fi + +if [[ "${where}" ]] +then + where="$1" +else + where='url LIKE "'"$1"'" ESCAPE "\" AND status = "skipped" AND try_count > 3' +fi -query='FROM queued_urls JOIN url_strings ON url_string_id = url_strings.id WHERE url LIKE "'"${urlpattern}"'" ESCAPE "\" AND status = "skipped" AND try_count > 3' +query='FROM queued_urls JOIN url_strings ON url_string_id = url_strings.id WHERE '"${where}" if [[ "${action}" == 'write' ]] then