Rsync Mikey & Kent
[clearscm.git] / bin / updateCalendar.sh
1 #!/bin/bash
2
3 wget -O /tmp/calendar.$$.ics https://calendar.google.com/calendar/ical/adefaria%40gmail.com/public/basic.ics > /tmp/updateCalendar.$$.log 2>&1
4 wget -O /tmp/meetups.$$.ics 'http://www.meetup.com/events/ical/10426135/8dfdd0ffaaedecf720c5faf0cf3871b7ee5f5c1e/going' >> /tmp/updateCalendar.$$.log 2>&1
5 wget -4 -O /tmp/tripit.$$.ics 'http://www.tripit.com/feed/ical/private/06C4F90D-EFEFB9C5FDB17EC5FCB327DE31A54D96/tripit.ics' >> /tmp/updateCalendar.$$.log 2>&1
6
7 # Now let's combine the files. First strip off the END:CALENDAR from the main 
8 # file.
9 filesize=$(wc -l /tmp/calendar.$$.ics | cut -f1 -d' ')
10 let lines=filesize-1
11 head -n $lines /tmp/calendar.$$.ics > /tmp/calendar2.$$.ics
12 mv /tmp/calendar2.$$.ics /tmp/calendar.$$.ics
13
14 # Now extract the middle of the next calendar
15 # Note, if we have nothing RSVPed here for Meetup then the file should be skipped.
16 # We will get an .ics file but it'll be short - less than 27 lines
17 filesize=$(wc -l /tmp/meetups.$$.ics | cut -f1 -d' ')
18
19 if [ $filesize -gt 27 ]; then
20   let lines=filesize-27
21
22   # Get the top portion...
23   tail -n $lines /tmp/meetups.$$.ics > /tmp/meetups2.$$.ics
24
25   # Now strip off END:VCALENDAR
26   let lines=filesize-27-1
27
28   head -n $lines /tmp/meetups2.$$.ics >> /tmp/calendar.$$.ics
29
30   # Clean up meetups2
31   rm -f /tmp/meetups2.$$.ics
32 fi
33
34 # Now extract the middle of the next calendar
35 filesize=$(wc -l /tmp/tripit.$$.ics | cut -f1 -d' ')
36
37 if [ $filesize -gt 27 ]; then
38   let lines=filesize-27
39
40   # Get the top portion...
41   tail -n $lines /tmp/tripit.$$.ics > /tmp/tripit2.$$.ics
42
43   # Now strip off END:VCALENDAR
44   let lines=filesize-27-1
45
46   head -n $lines /tmp/tripit2.$$.ics >> /tmp/calendar.$$.ics
47
48   # Cleanup tripit2
49   rm -f /tmp/tripit2.$$.ics
50 fi
51
52 # Now add END:VCALENDAR to calendar.ics
53 echo "END:VCALENDAR" >> /tmp/calendar.$$.ics
54
55 # Move into place
56 mv /tmp/calendar.$$.ics ~/Documents/calendar.ics
57
58 # Get rid of stupid CRs
59 dos2unix -q ~/Documents/calendar.ics
60
61 # Restart rainlendar2
62 export DISPLAY=:1
63 killall rainlendar2
64 rainlendar2 > /tmp/rainlendar2.log 2>&1 &
65
66 # Cleanup
67 rm -rf                  \
68   /tmp/meetups.$$.ics   \
69   /tmp/tripit.$$.ics    \
70   /tmp/updateCalendar.$$.log