#!/bin/sh set -e year="${1:-$(date +%Y)}" echo "Fetching for year: $year" current_time="$(date)" dir="programs/$year" mkdir -p "$dir" file_path="$dir/bornhack_program_$year_${current_time}" xml_path="$file_path.xml" json_path="$file_path.json" last_xml="$(ls -1 programs/$year/bornhack_program_*.xml 2>/dev/null | LC_ALL=C sort | tail -n 1)" last_json="${last_xml%.*}.json" curl "https://bornhack.dk/bornhack-$year/program/frab.xml" > "$xml_path" if [ -f "$last_xml" ]; then if diff -q -- "$xml_path" "$last_xml" >/dev/null; then echo "No change in program" # echo "Newly fetched program: $xml_path is the same as last program: $last_program, cleaning up last_program" rm -f -- "$last_xml" mv "$last_json" "$json_path" exit 0 fi fi echo 'New program content fetched' cat "$xml_path" | xq '.schedule.day | map(.room) | flatten | map(.event) | map(select(. != null)) | flatten | map({title, date, room, duration}) | sort_by(.date)' > "$json_path" if [ -f "$last_json" ]; then diff --color=always "$last_json" "$json_path" rm -f -- "$last_json" fi ln -sfr "$json_path" programs/current.json