-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathics-to-html.cron
More file actions
executable file
·199 lines (170 loc) · 6.81 KB
/
ics-to-html.cron
File metadata and controls
executable file
·199 lines (170 loc) · 6.81 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env bash
#
# Cron job to update schedule.html and the pages for the tracks with
# events from the W3C Calendar, using the ics-to-html.awk script.
#
# (The events in the W3C Calendar are typically put there by the TPAC
# organizers. In the case of breakouts, they use a process that first
# collects breakouts as GithUb issues and then converts them to
# calendar events. See https://github.com/w3c/tpac-breakouts )
#
# To add "fake" events that are not in the W3C Calendar, edit the file
# extra-events.ics.
#
# To add extra categories (class names) to events beyond the
# categories that are in the W3C Calendar, edit the Google Docs
# spreadsheet:
#
# https://docs.google.com/spreadsheets/d/1629ZDKKClOWJkk3XOYCtQ8_TsllEl586IMzoMzyEh_4/edit?usp=sharing
#
# Command line options:
#
# -n
# Run the commands, but do not actually update the pages. This is
# useful to see if the commands succeed without any errors.
# Implies -c.
# -c
# Do not check the updated pages into CVS.
# -f
# Force updates. Do not stop processing when a sanity check fails.
# Warning: This may result in incorrect files, unless combined
# with -n.
# -d directory
# The working directory, i.e., the directory in which to check out
# the relevant files from CVS. Default: $HOME/WWW/2025/11/TPAC
# -i url
# The URL of the ICS file with the relevant entries from the W3C
# group calendar. Default:
# https://www.w3.org/calendar/tpac2025/export/"
#
# Created: 26 February 2023
# based on https://www.w3.org/2022/09/TPAC/ics-to-html.cron
# Author: Bert Bos <bert@w3.org>
set -u -e
# The default URL for the relevant subset of the W3C calendar, in
# icalendar format.
CALENDAR="https://www.w3.org/calendar/tpac2025/export/"
# Labels (‘tracks’) to add to certain events. To get this URL for the
# Google spreadsheet, open the spreadsheet in a browser and go to
# "File" -> "Share" -> "Publish to web". That opens a dialog box.
# Make sure that the checkbox next to "Restrict access to the
# following" is *not* checked. Then select "Tab-separated values
# (.tsv)" from the second dropdown menu and copy the long URL that is
# shown in the text box under that menu. It looks like
# "https://docs.google.com/spreadsheets/d/.../pub?output=tsv".
#TRACKS="https://docs.google.com/spreadsheets/d/e/2PACX-1vTm2XjfBK0AeekT1xnT-x-acsV73JOZ9aVTvjcENrihNuQK10ghmUhAM_0k1NgqX_atuaN9B3kcMjal/pub?output=tsv"
TRACKS=
# The default directory with checked-out copies of all relevant files from CVS.
# DIR=$HOME/WWW/2025/11/TPAC
DIR=.
# Extra events that aren't in $CALENDAR:
EXTRAEVENTS=extra-events.ics
# The files to update.
SCHEDULES=(schedule.html coming-up.html)
# The files in SCHEDULES are allowed to grow by at most 50% or shrink
# by at most 30% (without the -f option). If the limits for some files
# should be different, set them in the MAXSHRINK and MAXGROW
# associative arrays.
declare -A MAXSHRINK=(coming-up.html 90)
declare -A MAXGROW=(breakouts.html 200 coming-up.html 650)
# The Awk script that puts the calendars in the pages + its helpers.
AWKSCRIPT=ics-to-html.awk
AWKLIBS=(markdown.awk htmlmathml.awk)
# A file that assigns group names to industry tracks. Uncomment this
# to label events with tracks whenever the event involves a group that
# belongs to an "ecosystem" named like the track. (Ecosystems are
# pages on the W3C web site.) See documentation inside the file for
# how the file is made.
#ECOSYSTEMS=ecosystems.txt
ECOSYSTEMS=
# An optional text to include as a comment in the generated HTML.
COMMENT="Generated by $0 running as user ${LOGNAME:-$USER} on ${HOSTNAME:-$(hostname)}"
# An optional HTML fragment to include if a calendar is empty. Each
# page can have its own text.
declare -A EMPTYTEXT=(
schedule.html "<span>(under construction)</span>"
coming-up.html "<span>(no events)</span>")
# The HTML pages are assumed to be in US English and encoded in UTF-8.
# When the Awk program outputs dates and times, they must be in US
# English, too.
export LC_CTYPE=en_US.UTF-8
export LC_TIME=en_US.UTF-8
trap 'cat $LOG; rm -f $LOG $ICS $HTML $EXTRACATEGORIES' 0
LOG=$(mktemp /tmp/ics-to-html-log-XXXXXX) || exit 1
ICS=$(mktemp /tmp/ics-to-html-ics-XXXXXX) || exit 1
HTML=$(mktemp /tmp/ics-to-html-html-XXXXXX) || exit 1
EXTRACATEGORIES=$(mktemp /tmp/ics-to-html-html-XXXXXX) || exit 1
# Command line options.
do_cvs=true
dry_run=false
force=false
while getopts "cd:fi:n" opt; do
case $opt in
c) do_cvs=false;;
d) DIR=$OPTARG;;
f) force=true;;
i) CALENDAR=$OPTARG;;
n) dry_run=true; do_cvs=false;;
?) exit 1;;
esac
done
# Capture error messages
exec 2>$LOG
# Define functions for progress reports and errors:
# trace -- print a message, but only if we are running in a terminal
# die -- print message and exit
# error -- print a warning (if $force=true) or print an error and exit
if tty -s; then function trace { printf "%s\n" "$@"; }
else function trace { :; }; fi
function die { printf "%s\n" "$*" >&2; exit 1; }
if $force; then function error { printf "Warning: %s\n" "$*" >&2; }
else function error { printf "Error: %s\n" "$*" >&2; exit 1; }; fi
# On MacOS, the awk isn't GNU awk. But MacPorts has it, under the name gawk.
if type -t gawk >/dev/null; then awk=gawk; else awk=awk; fi
trace "- Go to $DIR"
cd $DIR
trace "- Try to load SSH keys, if they exist."
[ -d ~/.keychain ] && . ~/.keychain/$(uname -n)-sh
# trace "- Update required files from CVS."
# cvs -Q up $EXTRAEVENTS $AWKSCRIPT "${AWKLIBS[@]}" $ECOSYSTEMS \
# "${SCHEDULES[@]}" || die "CVS update failed. Is there a CVS conflict?"
trace "- Get $CALENDAR"
curl -f -L -s "$CALENDAR" >$ICS || die "curl failed"
if [[ -z "$TRACKS" ]]; then
touch $EXTRACATEGORIES
else
trace "- Get tracks from Google Doc"
curl -f -L -s "$TRACKS" >$EXTRACATEGORIES || die "curl failed"
fi
# Loop over the schedule files.
for schedule in "${SCHEDULES[@]}"; do
trace "- Update $schedule"
trace " - Update from the calendar and the extras."
h=${EMPTYTEXT[$schedule]:-}
$awk ${COMMENT:+-v comment="$COMMENT"} ${h:+-v emptytext="$h"} -f $AWKSCRIPT \
$ICS $EXTRAEVENTS $EXTRACATEGORIES $ECOSYSTEMS $schedule >$HTML
trace " - Check that the result is plausible."
set -- $(wc -c <$schedule); oldsize=$1
set -- $(wc -c <$HTML); newsize=$1
shrink=${MAXSHRINK[$schedule]:-30}
grow=${MAXGROW[$schedule]:-50}
((minsize = (100 - shrink) * oldsize / 100))
((maxsize = (100 + grow) * oldsize / 100))
if ((newsize > maxsize)); then
error "$schedule has grown more than $shrink%."
fi
if ((newsize < minsize)); then
error "$schedule has shrunk more than $grow%."
fi
if ! cmp <(head $schedule) <(head $HTML); then
error "$schedule has unexpected text at start of file:"$'\n'"$(head $HTML)"
fi
if ! $dry_run; then
cat $HTML >$schedule
fi
done
# if $do_cvs; then
# trace "- Commit files into CVS."
# cvs -Q com -m "Updated by $0" "${SCHEDULES[@]}"
# fi
trace "- Done"