diff options
Diffstat (limited to 'fetch_program.sh')
| -rwxr-xr-x | fetch_program.sh | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/fetch_program.sh b/fetch_program.sh index 526e194..4a93b0a 100755 --- a/fetch_program.sh +++ b/fetch_program.sh @@ -14,25 +14,31 @@ last_json="${last_xml%.*}.json" curl "https://bornhack.dk/bornhack-$year/program/frab.xml" > "$xml_path" +symlink() { + ln -sfr "$json_path" "programs/next.json" + mv --no-copy "programs/next.json" "programs/current.json" + stat -c %N programs/current.json +} + + if [ -f "$last_xml" ]; then - if diff -q -- "$xml_path" "$last_xml" >/dev/null; 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" + symlink exit 0 fi fi -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" +cat "$xml_path" | xq '.schedule.day | map(.room) | flatten | map(.event) | map(select(. != null)) | flatten | 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/next.json" -mv --no-copy "programs/next.json" "programs/current.json" +symlink echo 'New program content fetched' -stat -c %N programs/current.json |
