Source: site.view [edit]
Function name: extendMetacritic
Arguments: rssFeed
Description:
Page type: webl
Render function:  
Module: sandbox

Page source:

var P = GetURL(rssFeed);

// var P = WubCall("metaPage2", []);

var s = Markup(P);
s = Wub_ReplaceAll(s, "<[CDATA[", "");
s = Wub_ReplaceAll(s, "<![CDATA[", "");
s = Wub_ReplaceAll(s, "& ", "&amp;");
s = Wub_ReplaceAll(s, "]]>", "");
P = NewPage(s, "text/xml");
var piece;

var Items = Elem(P, "item");

var list = [];

var clean = fun(s)
   s = Wub_ReplaceAll(s, "& ", "&amp;");
   return s
end;

every item in Items do
   var Title = Elem(P, "title") inside item;
   var Link = Elem(P, "link") inside item;
   var review = "none";
   if (Size(Link) == 1) then
      var title = Str_Trim(Text(Title[0]));
      var url = Str_Trim(Text(Link[0]));
      list = list + [[title, url]];

      var s = "";    // <reviews>\n";
      review = WubCall("metacriticReviews", [title, url] ) ? nil;
      if (review != nil and !Stringp(review)) then
         piece = NewPiece("<metascore>" + review.metascore 
             + "</metascore>", "text/html");
         InsertAfter(EndTag(Link[0]), piece);
         piece = NewPiece("<userscore>" + review.userscore
             + "</userscore>", "text/html");
         InsertAfter(EndTag(Link[0]), piece);
         every r in review.reviews do
            s = s + " <review>\n";
            s = s + "  " + "<score>" + r.score+ "</score>\n";
            s = s + "  " + "<criticname >" + r.criticname + "</criticname >\n";
            s = s + "  " + "<publication>" + r.publication+ "</publication>\n";
            s = s + "  " + "<reviewurl>" + r.reviewurl+ "</reviewurl>\n";
            s = s + "  " + "<quote>" + clean(r.quote)+ "</quote>\n";
            s = s + " </review>\n";
         end
      else
        s = s + "<error>" + "Error loading reviews for: " + title + "</error>\n";
      end;
      // s = s + "</reviews>\n";
      piece = NewPiece(s, "text/html");
      InsertAfter(EndTag(Link[0]), piece);
   end;
end;

Pretty(P);