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.
 
 
 

56 lines
1.7 KiB

  1. #!/bin/bash
  2. # Usage: wpull2-requeue [ACTION] [FILENAME] [--where] URLPATTERN_OR_WHERE
  3. # ACTION can be 'count' (default), 'print', or 'write'. On 'write', the number of modified records is printed.
  4. # FILENAME defaults to 'wpull.db'
  5. # URLPATTERN_OR_WHERE is URLPATTERN if --where isn't used or WHERE if it is.
  6. # 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.
  7. # Must not contain quotes.
  8. # WHERE is an arbitrary SQLite 'WHERE' condition. The available tables are 'queued_urls' and 'url_strings', already joined together.
  9. if [[ $# -eq 4 || ( $# -ge 2 && $# -le 3 && ( "$1" == 'count' || "$1" == 'print' || "$1" == 'write' )) ]]
  10. then
  11. action="$1"
  12. shift
  13. else
  14. action=count
  15. fi
  16. if [[ $# -eq 3 || ( $# -eq 2 && "$1" != '--where' ) ]]
  17. then
  18. filename="$1"
  19. shift
  20. else
  21. filename=wpull.db
  22. fi
  23. if [[ ! -f "${filename}" ]]
  24. then
  25. echo "Error: ${filename} does not exist or is not a regular file" >&2
  26. exit 1
  27. fi
  28. where=
  29. if [[ "$1" == '--where' ]]
  30. then
  31. where=1
  32. shift
  33. fi
  34. if [[ "${where}" ]]
  35. then
  36. where="$1"
  37. else
  38. where='url LIKE "'"$1"'" ESCAPE "\" AND status = "skipped" AND try_count > 3'
  39. fi
  40. query='FROM queued_urls JOIN url_strings ON url_string_id = url_strings.id WHERE '"${where}"
  41. if [[ "${action}" == 'write' ]]
  42. then
  43. sqlite3 "${filename}" 'UPDATE queued_urls SET status = "todo", try_count = 0, status_code = NULL WHERE id IN (SELECT queued_urls.id '"${query}"'); SELECT changes()'
  44. elif [[ "${action}" == 'print' ]]
  45. then
  46. sqlite3 "${filename}" "SELECT queued_urls.*, url_strings.* ${query}"
  47. else
  48. sqlite3 "${filename}" "SELECT COUNT(queued_urls.id) ${query}"
  49. fi