blob: 526e19430edf29f3197640fd6824a6e54955b299 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#!/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
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/next.json"
mv --no-copy "programs/next.json" "programs/current.json"
echo 'New program content fetched'
stat -c %N programs/current.json
|