Wednesday 30 November 2011

Christmas Lights

Our first Christmas since moving to Portishead is coming up, and the lights were switched on on Monday. It's nice to see how festive the high street looks with a bit of extra colour, and no gaudy flashing snowflakes or Santas here thank you!

I'm not sure the phone camera photo really does it justice though.

Let the counting down begin!

Tuesday 8 November 2011

Pulling Blogger content into Google Sites with Google Apps Script

You may remember that I migrated the Heswall Disabled Children's Holiday Fund website to Google Apps a couple of weeks ago, and started to use Google Sites for the web pages.

One of the things I'd been wanting to do for the camp is create a blog where news and developments can be published. Google Sites offers an "Announcement" page type, but it's not really as nice to work with a Blogger, as I had discovered here already. But the trouble with trying to combine a Blogger blog with a Google Sites website, is that both use templates neither of which can easily be made to be part of the other.

The solution I came up with is to use Blogger for writing the blog, but have the RSS feed published into a Google Sites page. Conveniently, Google provides a scripting toolset, Google Apps Script (apparently this doesn't have anything to do with Google Apps, the service, but with Google apps, the suite of applications), that allows JavaScript access to the Sites object model (amongst other things).

Here's the script I came up with:

function loadContent() {
  // ... Initialisation ...
  var feedDocument = Xml.parse(UrlFetchApp.fetch(rssUrl).getContentText(), false);
  var feedUpdated = feedDocument.feed.updated.getText();
  var pageUpdated = CacheService.getPublicCache().get("updated");
  CacheService.getPublicCache().put("updated", feedUpdated, 4800);

  if (feedUpdated == pageUpdated) {
  var site = SitesApp.getSite(domainName, siteName);
  var page = site.getChildByName(pageName);
  var template = getTemplate(site.getTemplates());
  var entriesArray = feedDocument.getElement().getElements("entry");
  var newPageHTML = "";
  for (var i = 0; i < entriesArray.length && i < numberPosts; i++) {
    var entry = entriesArray[i];

    newPageHTML = newPageHTML + "<div>"+
      "<h3><a href='"+getLink(entry)+"'>"+entry.title.getText()+"</a></h3>"+
      "<div style='font-size:0.8em;background-color:#E7E7E7'>Posted by "" on "+getDate(entry)+"</div>"+
  if (entriesArray.length > numberPosts) {
    newPageHTML = newPageHTML + "<p><a href='"+blogspotUrl+"'>View older posts</a></p>";
  newPageHTML = newPageHTML + "<p><a href='"+rssUrl+"'>Subscribe to Posts (Atom)</a></p>"
  page.setHtmlContent(template.getHtmlContent().replace(/<br[^>]*>/i, newPageHTML));

function getTemplate(templates) {
  var templateName = ScriptProperties.getProperty("templateName");
  for (var i = 0; i < templates.length; i++) {
    var t = templates[i];
    if (t.getPageType() == PageType.WEB_PAGE && t.getName() == templateName) {
      return t;

function getLink(entry) { ... } // Gets the right link from the entry
function getDate(entry) { ... } // Parses and formats the published date
Pretty simple, and seems to work ok. Admittedly at the time of writing, there's only one entry to publish, but I don't think more should be a problem.

Wednesday 2 November 2011

Arthur Overload

I'm a big fan of the legends of King Arthur - when I was at school I never really liked history much, and gave it up as soon as I could. In the last year that I had to do it (aged 13), part of the year's work was to do a "research project" on some event in history, and I chose to weigh up the truth in the legends. Having never really managed any better than the bare minimum of necessary homework, I'm not sure the teacher entirely believed it was my own work when I got one of the highest marks in the school. I still have the report I wrote - maybe one day I'll type it up for posterity.
At the moment, though, I seem to be suffering what could almost be said to be a bit of overload...
First there was Mary Stewart's Crystal Cave trilogy, which I read on and off over about 3 months last year. The story is the life story of Merlin, rather than Arthur. It's a good trilogy, with quite a believable mixture of magical legend and what can easily be believed as the hardships that people living in the first millennium A.D. might have had to put up with.
Next, there's the BBC's Merlin, now in its fourth season on BBC1. A more light-hearted take on the stories would be hard to find, and yet the main characters of Uther, Arthur, Merlin, Morgana, Guinevere (or Gwen) and others are familiar, as are some of the storylines for each of them.
Then after being given a Kindle 3 for Christmas last year, I downloaded Bernard Cornwell's Winter King - the first in a trilogy about Arthur, which I'm about 90% through, and I'm certainly enjoying his portrayal of Arthur as a successful warlord at a time of many Briton tribes fighting off attacks from the invading Saxons.
If those three different versions of the same stories weren't enough, Channel 4 brought out a new Arthur TV series, Camelot - which I mostly missed when it was first aired, and is now being repeated on More 4, and I've got set on Series-Link record - hopefully the stories will be good, and Channel 4 "Drama" won't have relied too much on the raunchy scenes featuring Morgan and Guinevere - not that they're bad scenes, it's just nice to think you're watching something better than a tabloid newspaper.
If you're a fan of historical fiction, I heartily recommend the Mary Stewart trilogy, and if the first book is anything to go by you wouldn't do badly from the Bernard Cornwell books either, although if you've read other books by him the formula will be familiar!
Right, I'm off to go and catch up on Merlin!