Skip to content

Instantly share code, notes, and snippets.

@alifeee
Created February 8, 2024 15:15
Show Gist options
  • Save alifeee/2eb9ac2296a698dc8a05d4ed531d8d36 to your computer and use it in GitHub Desktop.
Save alifeee/2eb9ac2296a698dc8a05d4ed531d8d36 to your computer and use it in GitHub Desktop.
Squarespace RSS combiner
#!/bin/bash
# combines SquareSpace RSS feeds
# Squarespace default feed (e.g., https://www.treehousesheffield.com/events?format=rss) only returns the current month
# This script fetches the current month and the next two months and combines them into a single RSS feed
# The script is intended to be run as a cron job
# It should work for any SquareSpace site (assuming they use the same query variable format)
# usage e.g.,
# ./combinerss.sh https://www.treehousesheffield.com/events?format=rss > /var/www/html/treehousesheffield.com/events.rss
# get today month and year
today=$(date +"%Y-%m-%d")
year=$(date +"%Y")
month=$(date +"%m")
if [ -z "$1" ]; then
echo "Usage: $0 <baseurl>"
exit 1
fi
baseurl=$1
months_ahead=3
all_rss=""
for i in $(seq 1 $months_ahead)
do
querystring="month=$(printf %02d $month)-$year"
# fetch the file
rss=$(curl -s "${baseurl}&${querystring}" | tr -d '\n')
# remove header with "<\?xml.*?<\/description>"
if [ $i -ne 1 ]; then
rss=$(echo $rss | perl -pe 's/<\?xml.*?<\/description>//g')
fi
# remove footer
if [ $i -ne $months_ahead ]; then
rss=$(echo $rss | sed 's/<\/channel><\/rss>//g')
fi
all_rss="$all_rss$rss"
month=$((month+1))
if [ $month -gt 12 ]; then
month=1
year=$((year+1))
fi
done
echo $all_rss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment