From 7b8b244d074ca1639ae61332a086c78a22474857 Mon Sep 17 00:00:00 2001 From: "user@node5.net" Date: Tue, 23 Jun 2026 00:36:12 +0200 Subject: nice program fetcher script --- fetch_program.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 fetch_program.sh (limited to 'fetch_program.sh') diff --git a/fetch_program.sh b/fetch_program.sh new file mode 100755 index 0000000..91684ac --- /dev/null +++ b/fetch_program.sh @@ -0,0 +1,37 @@ +#!/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 + -- cgit v1.3.1