diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 10 | ||||
| -rwxr-xr-x | fetch_program.sh | 37 |
3 files changed, 38 insertions, 10 deletions
@@ -2,3 +2,4 @@ program.json program.xml __pycache__ venv +programs diff --git a/Makefile b/Makefile deleted file mode 100644 index 7794a17..0000000 --- a/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -.PHONY: update_progam program.xml program.json - -src/program.xml: - curl https://bornhack.dk/bornhack-2025/program/frab.xml > src/program.xml - -src/program.json: - cat src/program.xml | xq '.schedule.day | map(.room) | flatten | map(.event) | map(select(. != null)) | flatten | map({title, date, room, duration}) | sort_by(.date)' > src/program.json - -update_progam: src/program.xml src/program.json - 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 + |
