Skip to content

Instantly share code, notes, and snippets.

@nicolassmith
Last active January 6, 2017 21:30
Show Gist options
  • Select an option

  • Save nicolassmith/fa7c20182ca376705c5b to your computer and use it in GitHub Desktop.

Select an option

Save nicolassmith/fa7c20182ca376705c5b to your computer and use it in GitHub Desktop.
ligo caltech journal club script
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" />
<html>
<head>
<title>LIGO CIT Journal Club</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
</head>
<body>
<h1><a href="https://wiki-40m.ligo.caltech.edu/Journal_Club">LIGO CIT Journal Club</a></h1>
<h2>Upcoming presenters:</h2>
<table border=1 cellspacing="0" cellpadding="5">
<?php
$nup = $_GET['nup'];
/* if ($nup == '') */
/* $nup = 20; */
$offset = $_GET['offset'];
/* if ($offset == '') */
/* $offset = 0; */
$cmd = './jchosts ' . $nup . ' ' . $offset;
exec($cmd, $output, $ret);
foreach ($output as $line) {
$info = explode(' ', $line, 2);
echo '<tr>';
echo '<td>';
echo $info[0];
echo '</td>';
echo '<td>';
echo $info[1];
echo '</td>';
echo '</tr>';
}
?>
</table>
<br />
<a href="jchosts">jchosts script</a>
</body>
</html>
#!/bin/bash -e
# LIGO Caltech Journal Club presenter picker
# https://wiki-40m.ligo.caltech.edu/Journal_Club
ROOT=$(dirname "$0")
IFS=$'\n'
# people in journal club
#PEOPLE=($(cat "$ROOT"/people | grep -v '^[[:space:]]*#'))
PEOPLE=(
'Aidan'
'Patricia'
'Eric G'
'Nicolas'
'Koji'
'Bill'
'Larry'
'Gabriele'
'Eric Q'
'Rana'
'Alastair'
'Rory'
'W. Zach'
'Max'
'Alan'
'Chris'
'Matt'
'Surabhi'
'Craig'
'Jamie'
'Xiaoyue'
'Kate'
'Tjonnie'
'Tom'
)
# List of journal club to be excluded (due to holidays, etc.). Past
# dates can be removed, but the PHASE will probably need to be
# adjusted to keep the phase.
# EXCLUDES=($(cat "$ROOT"/exclude_dates | grep -v '^[[:space:]]*#'))
EXCLUDES=(
2015/07/03
2015/11/27
2015/12/25
2016/01/01
2016/11/25
2016/12/23
2016/12/30)
# This adjusts the phase of the presenters relative to the epoch.
# Useful for retaining upcoming ordering when people are added to
# list or past exclude dates are removed.
PHASE=${PHASE:=-21}
# List address
TO=${TO:='[email protected]'}
FROM="Journal Club Overlord <[email protected]>"
REPLYTO="LIGO Journal Club <[email protected]>"
###################################################
usage() {
cat <<EOF
LIGO Caltech Journal Club presenter picker:
$(basename $0) [-d|-s] [NUP [OFFSET]]
This script figures out who is presenter for a given week, and sends
an email to the list.
NUP how many upcoming weeks to list
OFFSET offset in weeks relative to the current week
-d mail dry run, outputs email to stdout
-m send email reminder
EOF
}
offset2date() {
date -d "$1 week friday" +"%Y/%m/%d"
}
weekssinceepoch() {
local seconds=$(date -d "$1" +%s)
echo "$seconds / 3600 / 24 / 7" | bc
}
count_excluded() {
local date="$1"
local ds=$(date -d "$date" +%s)
local nexcluded=0
for e in ${EXCLUDES[@]} ; do
es=$(date -d "$e" +%s)
if ((ds > es)); then
(( nexcluded++ ))
fi
if ((ds == es)); then
echo $nexcluded
return 0
fi
done
echo $nexcluded
return 1
}
date2name() {
local date="$1"
local week=$(weekssinceepoch "$date")
local nexcluded
local msg
local ind
if nexcluded=$(count_excluded "$date") ; then
msg="NO MEETING"
fi
# This is the picker algorithm
ind=$(( (week - nexcluded - PHASE) % ${#PEOPLE[@]} ))
if [ -z "$msg" ] ; then
msg="${PEOPLE[ind]}"
fi
if [ "$DEBUG" ] ; then
echo "$nexcluded" "$ind" "$msg"
else
echo "$msg"
fi
}
format_msg() {
local date="$1"
printf '%s %s\n' "$date" "$(date2name "$date")"
}
###################################################
unset SEND
OUT=list
if [[ "$1" == '-m' ]] ; then
SEND=true
OUT=none
shift
elif [[ "$1" == '-d' ]] ; then
OUT=mail
shift
elif [[ "$1" == '-h' ]] ; then
usage
exit
fi
nup=${1:-${#PEOPLE[@]}}
offset=${2:-0}
next_date=$(offset2date "$offset")
next_person="$(date2name "$next_date")"
###################################################
if [[ "$OUT" == 'list' ]] ; then
for uc in $(seq 0 $((nup - 1))) ; do
format_msg $(offset2date "$((offset+uc))")
done
exit
fi
###################################################
# The email message
if [[ "$next_person" == 'NO MEETING' ]] ; then
subject="No journal club this week"
msg="Enjoy your vacation!
"
else
subject="This week's journal club: $next_person"
msg="This week's journal club presenter ($next_date) is:
$next_person
$next_person, please pick an interesting article to present this week,
post a link to it on the wiki:
https://wiki-40m.ligo.caltech.edu/Journal_Club
and let everyone know (BY TUESDAY!) by replying to this message.
Thanks!
"
fi
msg+="Upcoming:
"
for uc in $(seq 1 "$nup"); do
msg+=$(format_msg $(offset2date "$((offset+uc))"))
msg+='\n'
done
msg+="
LIGO Journal Club
Friday, 2:30pm
265, 2nd floor of W Bridge"
###################################################
if [[ "$OUT" == 'mail' ]] ; then
echo "From: $FROM"
echo "To: $TO"
echo "Subject: $subject"
echo
echo -e "$msg"
fi
if [[ "$SEND" == 'true' ]] ; then
printf "sending email..." >&2
echo -e "$msg" | \
mailx \
-s "$subject" \
-S from="$FROM" \
-S replyto="$REPLYTO" \
"$TO"
printf " sent.\n" >&2
fi
@rxa254
Copy link
Copy Markdown

rxa254 commented Jan 6, 2017

Holy Frijole! Bash??!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment