The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

42 lines
1.2 KiB

  1. #!/bin/bash
  2. # Usage: wpull2-requeue [ACTION] [FILENAME] URLPATTERN
  3. # ACTION can be 'count' (default), 'print', or 'write'
  4. # FILENAME defaults to 'wpull.db'
  5. # 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.
  6. # Must not contain quotes.
  7. if [[ $# -eq 3 || ( $# -eq 2 && ( "$1" == 'count' || "$1" == 'print' || "$1" == 'write' )) ]]
  8. then
  9. action="$1"
  10. shift
  11. else
  12. action=count
  13. fi
  14. if [[ $# -eq 2 ]]
  15. then
  16. filename="$1"
  17. shift
  18. else
  19. filename=wpull.db
  20. fi
  21. if [[ ! -f "${filename}" ]]
  22. then
  23. echo "Error: ${filename} does not exist or is not a regular file" >&2
  24. exit 1
  25. fi
  26. urlpattern="$1"
  27. 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'
  28. if [[ "${action}" == 'count' ]]
  29. then
  30. sqlite3 "${filename}" "SELECT COUNT(queued_urls.id) ${query}"
  31. elif [[ "${action}" == 'print' ]]
  32. then
  33. sqlite3 "${filename}" "SELECT queued_urls.*, url_strings.* ${query}"
  34. else
  35. sqlite3 "${filename}" 'UPDATE queued_urls SET status = "todo", try_count = 0 WHERE id IN (SELECT queued_urls.id '"${query}"')'
  36. fi