#!/bin/bash # Set the URL of the Atom feed feed_url="https://fediverse.observer/new-servers.xml" # Set the interval for checking for updates (in seconds) interval=600 # Initialize last_update variable last_update="" while true; do # Get the date of the last update from the feed feed=$(curl -Ls "$feed_url") 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 }') if [ -n "$update_dates" ]; then # Update the date of the last check last_update=$(echo "$update_dates" | head -1) # Get total count of last updated sites update_count=$(echo "$update_dates" | wc -l) # Parse the feed and get the link of the first entry 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}') for url in $urls; do cd /opt/fedi-block-api && sudo -Hu fba python3 fetch_instances.py "$url" done fi # Wait for the specified interval sleep $interval done