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.
 
 
 

33 lines
886 B

  1. #!/bin/bash
  2. # Usage: wpull2-url-origin [FILENAME] URL
  3. # FILENAME defaults to wpull.db
  4. # Trace back where a URL was discovered, all the way back to the root
  5. if [[ $# -eq 2 ]]
  6. then
  7. filename="$1"
  8. shift
  9. else
  10. filename=wpull.db
  11. fi
  12. if [[ ! -f "${filename}" ]]
  13. then
  14. echo "Error: ${filename} does not exist or is not a regular file" >&2
  15. exit 1
  16. fi
  17. url="$1"
  18. curId=$(sqlite3 "${filename}" 'SELECT id FROM url_strings WHERE url = "'"${url}"'"')
  19. if [[ -z "${curId}" ]]
  20. then
  21. echo "Error: ${url} not found" >&2
  22. exit 1
  23. fi
  24. while :
  25. do
  26. sqlite3 "${filename}" 'SELECT queued_urls.*, url_strings.* FROM queued_urls JOIN url_strings ON queued_urls.url_string_id = url_strings.id WHERE url_strings.id = '${curId}
  27. IFS='|' read -r curId level < <(sqlite3 "${filename}" 'SELECT parent_url_string_id, level FROM queued_urls WHERE url_string_id = '${curId})
  28. if [[ ${level} -eq 0 ]]
  29. then
  30. break
  31. fi
  32. done