Holiday fetching script
This commit is contained in:
parent
73500a0515
commit
35c18a1059
21
bin/fetch_holidays
Executable file
21
bin/fetch_holidays
Executable file
@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
_parse_ics=parse_ics
|
||||
if ! command -v "$_parse_ics" >/dev/null 2>/dev/null; then
|
||||
BOOKSQL_PATH="${BOOKSQL_PATH:-"$(dirname -- "$(dirname -- "$(readlink -f "$0")")")"}"
|
||||
_parse_ics="$BOOKSQL_PATH/bin/parse_ics"
|
||||
fi
|
||||
|
||||
# Bank holidays, where libraries are closed
|
||||
curl -s https://etalab.github.io/jours-feries-france-data/ics/jours_feries_metropole.ics |
|
||||
"$_parse_ics" |
|
||||
jq -r '._components[].dtstart[][]' |
|
||||
sed -E 's/^([0-9]{4})([[:digit:]]{2})([[:digit:]]{2})$/\1-\2-\3/; s/.*/INSERT OR REPLACE INTO holidays (start, end, closed) VALUES ('"'"'&'"'"', '"'"'&'"'"', TRUE);/'
|
||||
|
||||
# School holidays, where libraries are still open, sometimes under different schedules
|
||||
curl -s 'https://data.education.gouv.fr/api/explore/v2.1/catalog/datasets/fr-en-calendrier-scolaire/exports/ical?lang=fr&timezone=Europe%2FParis' |
|
||||
"$_parse_ics" |
|
||||
jq -r '[._components[] | select(._type == "VEVENT").description[][] | gsub("\\\\n"; "\n")]|join("\n\n")' |
|
||||
recsel -e 'population != "Enseignants" && location = "Grenoble"' |
|
||||
recfmt "INSERT INTO holidays (start, end, closed) SELECT SUBSTR('{{start_date}}', 0, 11), SUBSTR('{{end_date}}', 0, 11), FALSE; "
|
1
ics.jq → bin/parse_ics
Normal file → Executable file
1
ics.jq → bin/parse_ics
Normal file → Executable file
@ -1,3 +1,4 @@
|
||||
#!/usr/bin/jq -sRf
|
||||
# RFC 5545 (iCalendar) parser
|
||||
# ~lucidiot, 2023
|
||||
|
Loading…
Reference in New Issue
Block a user