Y 2019-10-01 20:34:53 +02:00
parent 2614107759
commit 193cc58443
2 changed files with 36 additions and 19 deletions

View File

@ -47,8 +47,10 @@ into entries like that:
``` ```
BEGIN:VEVENT BEGIN:VEVENT
DTSTART:20191001T130000+0200 UID:20191001T110000Z/epsi2ics/YOUR.LOGIN@HOSTNAME
DTEND:20191001T150000+0200 DTSTAMP:20191001T184200Z
DTSTART:20191001T110000Z
DTEND:20191001T130000Z
SUMMARY:HTLM5 / CSS3 SUMMARY:HTLM5 / CSS3
LOCATION:N202(HEP Nantes) LOCATION:N202(HEP Nantes)
DESCRIPTION:🗣 teacher name 👥 class-group name DESCRIPTION:🗣 teacher name 👥 class-group name

View File

@ -3,6 +3,9 @@
# Copyright © 2019 Y. Gablin, under the GPL-3.0-or-later license. # Copyright © 2019 Y. Gablin, under the GPL-3.0-or-later license.
# Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing. # Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing.
# #
# This script only works when executed in the timezone of the calendar, and only if this timezone offset
# is low enough to keep all events in the day they belong to in the web calendar (usually 6h ≤ TZ ≤ +8h).
#
# from EPSI “edtmobilityeng” to ICS, for the current school year # from EPSI “edtmobilityeng” to ICS, for the current school year
# $1: EPSI Login (firstname.lastname) # $1: EPSI Login (firstname.lastname)
# $2: output file (else standard output) # $2: output file (else standard output)
@ -12,6 +15,7 @@ if [ -n "$2" -a -d "$(dirname "$2")" -a -w "$(dirname "$2")" ]; then
fi fi
( (
dtstamp=$(date -u +%Y%m%dT%H%M%SZ)
currentYear=$(date +%Y) currentYear=$(date +%Y)
splitDay=$(date +%j -d "${currentYear}-08-01" | sed 's/^0*//') # XXXX-08-01 ∈ [1 … 366] splitDay=$(date +%j -d "${currentYear}-08-01" | sed 's/^0*//') # XXXX-08-01 ∈ [1 … 366]
dayOfYear=$(date +%j | sed 's/^0*//') # this day ∈ [1 … 366] dayOfYear=$(date +%j | sed 's/^0*//') # this day ∈ [1 … 366]
@ -27,7 +31,7 @@ fi
cat <<-ENDOFTEXT cat <<-ENDOFTEXT
BEGIN:VCALENDAR BEGIN:VCALENDAR
VERSION:2.0 VERSION:2.0
PRODID:yalis.fr/epsi2ical v1.0/FR PRODID:yalis.fr/epsi2ical v1.1
ENDOFTEXT ENDOFTEXT
while [ $offset -lt $offsetMax ]; do while [ $offset -lt $offsetMax ]; do
@ -41,23 +45,32 @@ ENDOFTEXT
| tr '\r\n' ' ' \ | tr '\r\n' ' ' \
| sed -r 's/[[:blank:]]+/ /g' \ | sed -r 's/[[:blank:]]+/ /g' \
| grep -oE '<DIV [^>]*class="Case" [^>]*style="[^"]*left *:[^"]*"|DIV [^>]*style="[^"]*left *:[^"]*" [^>]*class="Case"|<td [^>]*class="TC(ase|Prof|hdeb|Salle)"([^<]|<[^/]|</[^t]|</t[^d])*</td>' \ | grep -oE '<DIV [^>]*class="Case" [^>]*style="[^"]*left *:[^"]*"|DIV [^>]*style="[^"]*left *:[^"]*" [^>]*class="Case"|<td [^>]*class="TC(ase|Prof|hdeb|Salle)"([^<]|<[^/]|</[^t]|</t[^d])*</td>' \
| awk -vmon=$mon -vtue=$tue -vwed=$wed -vthu=$thu -vfri=$fri -F$'\t' ' | awk -vmon=$mon -vtue=$tue -vwed=$wed -vthu=$thu -vfri=$fri -vid="epsi2ics/${1}@${HOSTNAME}" -vdtstamp=$dtstamp -F$'\t' '
function out() { function out() {
if (ase!="") printf( \ if (from!="" && to!="" && ase!="") printf( \
"BEGIN:VEVENT\nDTSTART:%s%s%s\nDTEND:%s%s%s\nSUMMARY:%s\nLOCATION:%s\nDESCRIPTION:🗣 %s 👥 %s\nEND:VEVENT\n", \ "BEGIN:VEVENT\nUID:%s/%s\nDTSTAMP:%s\nDTSTART:%s\nDTEND:%s\nSUMMARY:%s\nLOCATION:%s\nDESCRIPTION:🗣 %s 👥 %s\nEND:VEVENT\n", \
day, from, zone, \ from, id, dtstamp, from, to, ase, where, prof, who)
day, to, zone, \ from=""
ase, \ to=""
where, \
prof, who)
ase="" ase=""
where=""
prof="" prof=""
who="" who=""
day="" day=""
zone="" zoneH=0
from="" zoneM=0
to="" }
where="" function toZtime(localH, localM) {
localM-=zoneM
if (localM<0) {
localM+=60
localH-=1
} else if (localM>59) {
localM-=60
localH+=1
}
localH-=zoneH
return sprintf("%s%02d%02d00Z", day, localH, localM)
} }
/class="Case"/ { /class="Case"/ {
out() out()
@ -68,7 +81,8 @@ ENDOFTEXT
else if (pc < 170) tmpd=thu else if (pc < 170) tmpd=thu
else tmpd=fri else tmpd=fri
day=substr(tmpd, 1, 9) day=substr(tmpd, 1, 9)
zone=substr(tmpd, 10) zoneH=substr(tmpd, 10, 3)+0
zoneM=(substr(tmpd, 10, 1) substr(tmpd, 13, 2))+0
} }
/class="TCase"/ { /class="TCase"/ {
ase=gensub(".*</div>(.*)</.*", "\\1", 1) ase=gensub(".*</div>(.*)</.*", "\\1", 1)
@ -79,9 +93,9 @@ ENDOFTEXT
who=tmp[2] who=tmp[2]
} }
/class="TChdeb"/ { /class="TChdeb"/ {
split(gensub(".*> *([^ ]{2}):?([^ ]{2}) *- *([^ ]{2}):?([^ ]{2}) *</.*", "\\1\\2\t\\3\\4", 1), tmp) split(gensub(".*> *0?([0-9]+):0?([0-9]+) *- *0?([0-9]+):0?([0-9]+) *</.*", "\\1\t\\2\t\\3\t\\4", 1), tmp)
from=tmp[1] "00" from=toZtime(tmp[1], tmp[2])
to=tmp[2] "00" to=toZtime(tmp[3], tmp[4])
} }
/class="TCSalle"/ { /class="TCSalle"/ {
where=gensub(".*>(Salle:)?(.*)</.*", "\\2", 1) where=gensub(".*>(Salle:)?(.*)</.*", "\\2", 1)
@ -96,4 +110,5 @@ ENDOFTEXT
END:VCALENDAR END:VCALENDAR
ENDOFTEXT ENDOFTEXT
) \ ) \
| env LANG=fr_FR@euro sed -r 's/(.{73})(.)/\1\n \2/g' \
| sed 's/$/\r/' | sed 's/$/\r/'