-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_edt_to_ical_UVSQ.sh
55 lines (45 loc) · 1.73 KB
/
convert_edt_to_ical_UVSQ.sh
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Variables pour le point d'entrée, les paramètres et la formation
URL='https://edt.uvsq.fr/Home/GetCalendarData'
FORMATION='MYCYB2_88'
DATA="start=2023-09-18&end=2024-09-23&resType=103&calView=agendaWeek&federationIds%5B%5D=$FORMATION&colourScheme=3"
# Fonction pour récupérer les données JSON
fetch_data() {
curl "$URL" --data-raw "$DATA" -s
}
# Fonction pour convertir les entités HTML
convert_html_entities() {
echo "$1" | sed -e 's/&/\&/g' \
-e 's/</</g' -e 's/>/>/g' \
-e 's/"/"/g' -e "s/'/'/g" \
-e "s/è/è/g" -e "s/é/é/g"
}
# Fonction principale pour traiter le JSON et afficher le format iCal
process_data() {
jq -rc '.[]' | while IFS= read -r event; do
id=$(echo "$event" | jq -r ".id")
start=$(echo "$event" | jq -r ".start" | sed 's/-//g' | sed 's/://g')
end=$(echo "$event" | jq -r ".end" | sed 's/-//g' | sed 's/://g')
description=$(echo "$event" | jq -r ".description" | sed 's/<br \/>/ /g' | tr -s '\n\r' ' ')
data=$(convert_html_entities "$description")
summary=$(echo "$data" | cut -d "]" -f2)
location=$(echo "$data" | cut -d "[" -f1)
echo "BEGIN:VEVENT"
echo "UID:$id"
echo "DTSTART;TZID=Europe/Paris:$start"
echo "DTEND;TZID=Europe/Paris:$end"
echo "SUMMARY:$summary"
echo "LOCATION:$location"
echo "DESCRIPTION:Mis à jour le $(date +'%d/%m/%Y %H:%M')"
echo "END:VEVENT"
done
}
# Exécution principale
echo "BEGIN:VCALENDAR"
echo "VERSION:2.0"
echo "PRODID:-//EDT M2 IRS Cyber - edit by Théo Peltier//EN"
echo "CALSCALE:GREGORIAN"
echo "METHOD:PUBLISH"
json_data=$(fetch_data)
echo "$json_data" | process_data
echo "END:VCALENDAR"