run_all.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. echo "Starting run at $(date -u +"%Y-%m-%d %H:%M:%S")"
  4. ONLY_LIST="${ONLY:-}" # e.g. "meandervalley" or "kentish,break_oday"
  5. SKIP_LIST="${SKIP:-}" # e.g. "hobartcity,latrobe"
  6. DEBUG_FLAG="${DEBUG:-}" # pass through to scrapers
  7. DRY_FLAG="${DRY_RUN:-}" # pass through to scrapers
  8. shopt -s nullglob
  9. SCRIPTS=(/app/scrapers/*.rb)
  10. should_run() {
  11. local name="$1"
  12. if [[ -n "$ONLY_LIST" ]]; then
  13. IFS=',' read -ra arr <<< "$ONLY_LIST"
  14. local pick
  15. for pick in "${arr[@]}"; do
  16. pick="${pick// /}"
  17. if [[ "$name" == "$pick" ]]; then
  18. echo "1"
  19. return
  20. fi
  21. done
  22. echo "0"
  23. return
  24. fi
  25. if [[ -n "$SKIP_LIST" ]]; then
  26. IFS=',' read -ra arr <<< "$SKIP_LIST"
  27. local skip
  28. for skip in "${arr[@]}"; do
  29. skip="${skip// /}"
  30. if [[ "$name" == "$skip" ]]; then
  31. echo "0"
  32. return
  33. fi
  34. done
  35. fi
  36. echo "1"
  37. }
  38. count=0
  39. for f in "${SCRIPTS[@]}"; do
  40. name="$(basename "$f" .rb)"
  41. table="da_${name}"
  42. if [[ "$(should_run "$name")" != "1" ]]; then
  43. continue
  44. fi
  45. echo "Running ${name} -> table ${table}"
  46. TABLE_NAME="$table" DEBUG="$DEBUG_FLAG" DRY_RUN="$DRY_FLAG" ruby "$f" || echo "Error in $f"
  47. count=$((count+1))
  48. done
  49. echo "Finished run at $(date -u +"%Y-%m-%d %H:%M:%S"). Ran ${count} scraper(s)."