Source: site.view [edit]
Function name: bacon
Arguments: actor
Description: Finds the bacon number of an actor and a list of bacon connections. Returns as XML
Page type: webl
Render function:  
Module: global

Page source:

var P = PostURL("http://oracleofbacon.org/movielinks.php", [. a = "Kevin Bacon", b = actor .]);

var BN = Pat(P, `has a Bacon number of (\d+)`);

var res = "<bacon>\n";

if Size(BN) > 0 then
   res = res + "  <number>" + BN[0][1] + "</number>\n"
end;
  
var T = Elem(P, "table") directlycontain Pat(P, "was in");
if Size(T) > 0 then
  var parent = Parent(T[0]);
  var Spans = Elem(P, "span") inside parent;
  var j = 0;
  res = res + "  <connections>\n";
  while j + 2 < Size(Spans) do
     var movieTitle = Str_Trim(Text(Spans[j+1]));
     var i = Str_IndexOf(`(`, movieTitle);
     if (i > 0) then
        movieTitle = Str_Trim(Select(movieTitle, 0, i));
     end;

     var actor1 = Str_Trim(Text(Spans[j]));
     i = Str_IndexOf(`(`, actor1);
     if (i > 0) then
        actor1 = Str_Trim(Select(actor1, 0, i));
     end;

     var actor2 = Str_Trim(Text(Spans[j+2]));
     i = Str_IndexOf(`(`, actor2);
     if (i > 0) then
        actor2 = Str_Trim(Select(actor2, 0, i));
     end;

     res = res + "    <connection>\n";
     res = res + "       <actor>" + actor1 + "</actor>\n";
     res = res + "       <inMovie>" + movieTitle + "</inMovie>\n";
     res = res + "       <withActor>" + actor2 + "</withActor>\n";
     res = res + "    </connection>\n";
     j = j + 2;
  end;
  res = res + "  </connections>\n";
end;

res = res + "</bacon>\n";

NewPage(res, "text/xml");