[Web4lib] How to feed Today's Library Hours to home page?

Thomas Bennett bennetttm at appstate.edu
Tue Apr 28 18:29:34 EDT 2009


Looks like you are a PHP site so for others interested that aren't PHP 
sites, GData API is still your friend.  I prefer the python  GData API 
seeing I am running Zope and Plone servers.

  Most calendars are populated by logging  into our Google Apps account 
and using their interface.  Below is a Python script to get events for one 
day and return HTML table, you will need to set a default start date to test 
this and of course have python and the GData API library and a google 
calendar account.

  There is one room calendar that is populated via python, PostgreSQL, WEB
forms, and cron for booking a room.  A cron job runs a python script that 
selects all approved events from a PostgreSQL database puts them up
on the Google Calendar and then changes a bool if the post was succesful
so it won't get that one again. 


The code below will return this:

"Events in Room 421 on 2009/05/04 
Monday May 04	09:00 AM - 10:30 am Web Advisory Council
Monday May 04	11:00 AM SECC meeting
Monday May 04	06:00 PM - 8:30 pm Theta Chi Fraternity


Special Collections Hours on 2009/05/04 Special Collections Hours
2009-05-04	Finals 
2009-05-04	8:00am-10:00pm"


for may 4, 2009 for use on an approval form for requesting the room. 
Actually it only returns the dates and descriptions, the labels above 
the dates are in the WEB form.  The room cannot be booked if Special
Collections is closed so that is why that is shown.

==========================================
#!/usr/local/bin/python

import gdata.calendar.service
import time
import string

def get_day_from_google_421(self,start_date):

  calendar_id='yourcalendaraddresshere at group.calendar.google.com'
  calendar_service = gdata.calendar.service.CalendarService()
  calendar_service.email = 'yourloginhere'
  calendar_service.password = 'yourpasswordhere'
  calendar_service.source = 'calendartitlehere'  #Title must match Google Calendar Title
  calendar_service.ProgrammaticLogin()

  # need days of each month so adding one day to last day changes to first day nextmonth
  months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
  sd=time.strptime(start_date, "%Y/%m/%d")
  start=time.strptime(start_date,'%Y/%m/%d')
  sd1=time.strftime('%Y-%m-%d',start)

  #make datetime a list to compare last day and add a day
  # google needs end date to be startdate+1 if it is not more than a one day event

  sdlist=list(sd)

  if sdlist[2]==months[sdlist[1]-1]:
    sdlist[2]=1     # set day =1
    sdlist[1]+=1  # add 1 to month
  else:
    sdlist[2]+=1  # or just add 1 to day if not month end

  ed=time.strftime('%Y-%m-%d',sdlist)  # set enddate to startdate+1
  my_info='<table>'
  newinfo=''
  query = gdata.calendar.service.CalendarEventQuery('yourcalendaraddress at group.calendar.google.com', 'private', 'full')
  query.start_min = sd1
  query.start_max = ed
  feed = calendar_service.CalendarQuery(query)
  for i, an_event in enumerate(feed.entry):
    for a_when in an_event.when:
      title=an_event.title.text
      datestring=a_when.start_time[0:-19]
      timestring=a_when.start_time[11:-13]
      b = time.strptime(timestring, "%H:%M")
      c = time.strptime(datestring,"%Y-%m-%d")
      newinfo = '<tr><td>%s</td><td>%s %s</td></tr>'%(time.strftime("%A %b %d",c),time.strftime("%I:%M %p",b),title)
      my_info=my_info+newinfo
  my_info=my_info+'</table>'
  return my_info


==========================================


All of our calendars in our site are iframes from Google, see: 
Room calendars
http://www.library.appstate.edu/services/schedule.html

Main Library Hours
http://www.library.appstate.edu/calendar/cal_library_hours

Music Library Hours
http://www.library.appstate.edu/calendar/cal_music

Today's events:
http://www.library.appstate.edu/library_events_today

Thomas
  


On Tuesday 28 April 2009 16:13:54 Andrew Darby wrote:
> We do this at my college, except the Google Calendar just functions as
> an administrative back-end.  I wrote up the technique here:
>
> http://journal.code4lib.org/articles/46
>
> We then run a cron job every night against the database to get today's
> hours for our home page.  I also use the Google Calendar data to
> generate a "Who's on the Desk Now (and When's Their Next Shift)" page:
>
> http://www.ithacalibrary.com/info/ref_hours.php
>
> On Tue, Apr 28, 2009 at 4:05 PM, John Fereira <jaf30 at cornell.edu> wrote:
> > Ingrid Redman wrote:
> >> Hello,
> >>
> >>
> >> I would like to display "Today's Open Hours" on our library home page in
> >> an
> >> automatic fashion.  Currently our hours are available in a google
> >> calendar (http://www.poly.edu/library/services/hours.php) and I was
> >> thinking I could
> >> set up a  feed to the home page with just today's hours, but I'm not
> >> sure how.
> >>
> >>
> >> Does anyone have experience doing this kind of thing with Google
> >> calendars?
> >> Or could you recommend another solution?  I'm not much of a coder.
> >
> > I am going to start working on this myself pretty soon.  In my case, we
> > want to be able set the "default hours" and then layer a number of
> > difference exceptions such as hours for weekends, spring/fall breaks,
> > summer hours, etc.  We also want to maintain a separate hours calendar
> > for our reference desk, and the cafe that is located in the building. to
> > complicate things further we not only want to be able to display hours on
> > the main web site, but also on a couple of display kiosks, AND it needs
> > to be callable as a service so that an equipment/room reservation system
> > that is being developed will be ablt to determine if an item is
> > reservable during a certain time period.  We have a bunch of of
> > reservable classroom and student study rooms that obviously can't be
> > reserved for a period when the library is closed.
> >
> >> Thanks for your help,
> >>
> >>
> >> Ingrid
> >>
> >>
> >> ________________________________________
> >>
> >> Ingrid Redman
> >>
> >> Web Librarian | Bern Dibner Library of Science and Technology
> >>
> >> Polytechnic Institute of NYU | 5 MetroTech Center | Brooklyn NY 11201
> >>
> >> Tel: 718 260 3672 | Fax: 718 260 3756 | Web:
> >>  <http://www.poly.edu/library>
> >> www.poly.edu/library
> >>
> >>
> >> _______________________________________________
> >> Web4lib mailing list
> >> Web4lib at webjunction.org
> >> http://lists.webjunction.org/web4lib/
> >
> > _______________________________________________
> > Web4lib mailing list
> > Web4lib at webjunction.org
> > http://lists.webjunction.org/web4lib/

-- 
==========================================
Thomas McMillan Grant Bennett           Appalachian State University
Operations & Systems Analyst            P O Box 32026
University Library                                Boone, North Carolina 28608
(828) 262 6587

Library Systems Help Desk: https://www.library.appstate.edu/help/
==========================================




More information about the Web4lib mailing list