Browse Source

Add --where for arbitrary conditions

master
JustAnotherArchivist 2 years ago
parent
commit
d57324a26c
1 changed files with 19 additions and 5 deletions
  1. +19
    -5
      wpull2-requeue

+ 19
- 5
wpull2-requeue View File

@@ -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


Loading…
Cancel
Save