Sfoglia il codice sorgente

Add --where for arbitrary conditions

master
JustAnotherArchivist 2 anni fa
parent
commit
d57324a26c
1 ha cambiato i file con 19 aggiunte e 5 eliminazioni
  1. +19
    -5
      wpull2-requeue

+ 19
- 5
wpull2-requeue Vedi File

@@ -1,11 +1,13 @@
#!/bin/bash #!/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' # ACTION can be 'count' (default), 'print', or 'write'
# FILENAME defaults to 'wpull.db' # 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. # 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. # 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 then
action="$1" action="$1"
shift shift
@@ -13,7 +15,7 @@ else
action=count action=count
fi fi


if [[ $# -eq 2 ]]
if [[ $# -eq 3 || ( $# -eq 2 && "$1" != '--where' ) ]]
then then
filename="$1" filename="$1"
shift shift
@@ -26,9 +28,21 @@ then
exit 1 exit 1
fi 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' ]] if [[ "${action}" == 'write' ]]
then then


Caricamento…
Annulla
Salva