update_fbadb_2.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Set the URL of the RSS feed
  3. feed_url="http://demo.fedilist.com/instance/newest/rss"
  4. # Set the interval for checking for updates (in seconds)
  5. interval=600
  6. # Initialize last_update variable
  7. last_update=""
  8. while true; do
  9. # Get dates of last updated sites from the feed
  10. feed=$(curl -Ls "$feed_url")
  11. update_dates=$(echo "$feed" | xmlstarlet sel -t -v "/rss/channel/item/pubDate" | awk -v date="$last_update" '{ if ($0 == date) exit; print }')
  12. if [ -n "$update_dates" ]; then
  13. # Update the date of the last check
  14. last_update=$(echo "$update_dates" | head -1)
  15. # Get total count of last updated sites
  16. update_count=$(echo "$update_dates" | wc -l)
  17. # Parse the feed and get the link of the entries
  18. urls=$(echo "$feed" | xmlstarlet sel -t -v "/rss/channel/item/title" | head -n "$update_count" | awk '{print $NF}' | sort | uniq -c | sort -nr | awk '{print $2}')
  19. for url in $urls; do
  20. cd /opt/fedi-block-api && sudo -Hu fba python3 fetch_instances.py "$url"
  21. done
  22. fi
  23. # Wait for the specified interval
  24. sleep $interval
  25. done