Source: site.view [edit]
Function name: findMovieTheaters
Arguments: zipcode
Description: A command to find movie theaters for a zipcode -> look up theaters for zipcode from Yahoo. Returns list of words for each theater name.
Page type: webl
Render function:   tlidRender
Module: global

Page source:

var P;
var loopResult;
var theaters;
var context;

context = NLUtil_InitContext();

//|| go to http://movies.yahoo.com
context = NLUtil_GetUrl(context, "http://movies.yahoo.com", nil, nil);
P = NLUtil_GetContext(context, `P`);

//|| find all forms that contain "Browse by Location"
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`form`, Elem(P, `form`)  contain Pat(P, `(?i)` + `Browse by Location`));

//|| field z is the zipcode
context = NLUtil_SetField(context, "z", zipcode);

//|| submit the form
context = NLUtil_submitForm(context);
P = NLUtil_GetContext(context, `P`);

//|| find all cells that directly contain "Add to My Favorite Theaters"
P = NLUtil_GetContext(context,`P`);
context = NLUtil_SetContext(context,`td`, Elem(P, `td`)  directlycontain Pat(P, `(?i)` + `Add to My Favorite Theaters`));

//|| for every cell
loopResult = [];
every td in NLUtil_GetContext(context, `td`) do
  td;

//||   find all words that are inside the cell
  P = NLUtil_GetContext(context,`P`);
  context = NLUtil_SetContext(context,`word`, Pat(P, `(\S)+\s`)    inside td);

//||   select all except for the last seven
  context = NLUtil_SetContext(context,NLUtil_LastType(context), Select(NLUtil_LastSet(context),0,Size(NLUtil_LastSet(context)) - 7));
  loopResult = loopResult + [NLUtil_LastSet(context)];
end;
NLUtil_SetContext(context, NLUtil_LastType(context), loopResult);

//|| call them theaters
theaters = NLUtil_LastSet(context);

if Size(OPTIONALARGS) == 0 then
   NLUtil_LastSet(context);
else
   context;
end;