update_fbadb_1.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Set the URL of the Atom feed
  3. feed_url="https://fediverse.observer/new-servers.xml"
  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 the date of the last update from the feed
  10. feed=$(curl -Ls "$feed_url")
  11. update_dates=$(echo "$feed" | xmlstarlet sel -N atom=http://www.w3.org/2005/Atom -t -v "//atom:entry/atom:published" | 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 first entry
  18. urls=$(echo "$feed" | xmlstarlet sel -N atom=http://www.w3.org/2005/Atom -t -v "//atom:entry/atom:link/@href" | head -n "$update_count" | awk -F'/' '{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