~nova/sharepoint-ical

c25f3161168381195adfd0ad8ba477a137ad2de4 — Novalinium 1 year, 8 months ago master
Initial release
3 files changed, 98 insertions(+), 0 deletions(-)

A README
A main.sh
A venv.pl
A  => README +31 -0
@@ 1,31 @@
**ABOUT
sharepoint-ical is a vanilla Bash/Perl program for generating an iCal/vCal feed from a Sharepoint site calendar.
**USAGE
# Assuming a calendar at https://sharepoint.fully.qualified.domain.name/Workspace/Lists/Group/Calendar.aspx, this would be
export CALBASE=sharepoint.fully.qualified.domain.name
bash main.sh Workspace Calendar [Group]
**BUGS
It does not support all attributes, only those displayed on month pages, and uses regexes to parse HTML because dammit, it was faster.
 
================================================================================
 
                             PUBLIC DOMAIN NOTICE
                 National Center for Biotechnology Information
 
  This software is a "United States Government Work" under the terms of the
  United States Copyright Act.  It was written as part of the author's official
  duties as a United States Government employees and thus cannot be copyrighted. 
  This software is freely available to the public for use. The National Library
  of Medicine and the U.S. Government have not placed any restriction on its use
  or reproduction.
 
  Although all reasonable efforts have been taken to ensure the accuracy and
  reliability of this software, the NLM and the U.S. Government do not and
  cannot warrant the performance or results that may be obtained by using this
  software. The NLM and the U.S. Government disclaim all warranties, expressed
  or implied, including warranties of performance, merchantability or fitness
  for any particular purpose.
 
  Please cite NCBI in any work or product based on this material.
 
================================================================================

A  => main.sh +40 -0
@@ 1,40 @@
#!/bin/bash
set -a
CALNS=${1:-IRB}
CALID=${2:-calendar1}
CALGROUP=${3:-Maintenance%20Schedules}
CALBASE=${CALBASE:-sp.${$(hostname)#*.*}}
SHAREPOINTDT=${SHAREPOINTDT:-"%m/%d/%Y %l:%M %p"}
LOOKAHEAD=${LOOKAHEAD:-6}
# If you edit this, add the new timezone spec below
TZ=America/New_York
set +a
cat <<EOF
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//sharepoint-ical//Sharepoint iCal Bridge 0.1//EN
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VTIMEZONE
TZID:America/New_York
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
EOF
curl -s --negotiate -u : https://$CALBASE/$CALNS/Lists/$CALGROUP/$CALID.aspx\?CalendarDate=$(date -v1d -v-1d +%m/01/%Y)\&CalendarPeriod=month $(seq 0 $LOOKAHEAD | xargs -I {} sh -c echo\ 'https://$CALBASE/$CALNS/Lists/$CALGROUP/$CALID.aspx\?CalendarDate=$(date -v1d -v+{}m +%m/01/%Y)\&CalendarPeriod=month') | \
fgrep DispForm.aspx | \
perl -pe 's/<td class="ms-.*?<a/\n<a/g; s/<a href=.*?aspx.id=(\d*).*?month .  title=./\n$1\t/g; s/'\'' .*//g; s/([AP]M) - /$1\t/g; s/([AP]M) /$1\t/g' | \
fgrep ':' | fgrep '	' | \
sort -u | \
perl venv.pl 
echo END:VCALENDAR

A  => venv.pl +27 -0
@@ 1,27 @@
#!/bin/perl -n
BEGIN{
use Time::Piece;
# TODO diff with last version of feed, or better still, retrieve from URL
$dtstamp = localtime->strftime("%Y%m%dT%H%M%SZ");
}
chomp;
@f = split /\t/;
$dtst = Time::Piece->strptime($f[1],$ENV{SHAREPOINTDT});
$dtnd = Time::Piece->strptime($f[2],$ENV{SHAREPOINTDT});
if ($dtst->strftime("%Y%m%d") eq $dtnd->strftime("%Y%m%d") and $dtst->strftime("%H%M") == 0 and $dtnd->strftime("%H%M") == 2359) {
	$dsec = "DTSTART;VALUE=DATE:" . $dtst->strftime("%Y%m%d");
} else {
	$dsec  = "DTSTART;TZID=$ENV{TZ}:" . $dtst->strftime("%Y%m%dT%H%M%S") . "\n";
	$dsec .= "DTEND;TZID=$ENV{TZ}:"   . $dtnd->strftime("%Y%m%dT%H%M%S");
}
$dtst = $dtst->epoch;
$dtnd = $dtnd->epoch;
print <<"EOF";
BEGIN:VEVENT
SUMMARY:$f[3]
UID:$ENV{CALNS}-$ENV{CALID}-$f[0]-$dtst-$dtnd\@$ENV{CALBASE}
DTSTAMP:$dtstamp
$dsec
URL:https://$ENV{CALBASE}/$ENV{CALNS}/Lists/$ENV{CALGROUP}/DispForm.aspx?id=$f[0]
END:VEVENT
EOF