update_fbadb_1.sh 975 B

123456789101112131415161718192021222324252627282930
  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. while true; do
  7. # Get the date of the last update from the feed
  8. last_update=$(curl -Ls "$feed_url" | grep -oP -m 1 "(?<=<updated>)[^<]+")
  9. # Compare the last update date with the date of the last check
  10. if [ "$last_update" != "$last_check" ]; then
  11. # Update the date of the last check
  12. last_check="$last_update"
  13. # Parse the feed and get the link of the first entry
  14. urls=$(curl -Ls "$feed_url" | xmlstarlet sel -N atom=http://www.w3.org/2005/Atom -t -v "//atom:entry/atom:link/@href" | awk -F'/' '{print $NF}' | sort | uniq -c | sort -nr | awk '{print $2}')
  15. for url in $urls; do
  16. cd /opt/fedi-block-api && sudo -Hu fba python3 fetch_instances.py $url
  17. done
  18. fi
  19. # Wait for the specified interval
  20. sleep $interval
  21. done