Collaborama About Help Contact Anonymous [login] Source: site.view [edit] Function name: findPhotos Arguments: term Description: A command to find photos for a term -> searches for images on Flickr -> Example inputs: term='flower' Page type: webl Render function: tlidRender Module: global Page source: var P; var loopResult; var context; context = NLUtil_InitContext(); //|| go to http://www.flickr.com context = NLUtil_GetUrl(context, "http://www.flickr.com", nil, nil); P = NLUtil_GetContext(context, `P`); //|| find all forms P = NLUtil_GetContext(context,`P`); context = NLUtil_SetContext(context,`form`, Elem(P, `form`) ); //|| field q is the term context = NLUtil_SetField(context, "q", term); //|| submit the form context = NLUtil_submitForm(context); P = NLUtil_GetContext(context, `P`); //|| find all rows that contain the term P = NLUtil_GetContext(context,`P`); context = NLUtil_SetContext(context,`tr`, Elem(P, `tr`) contain Pat(P, `(?i)` + term)); //|| for every row loopResult = []; every tr in NLUtil_GetContext(context, `tr`) do tr; //|| find all images that are inside the row P = NLUtil_GetContext(context,`P`); context = NLUtil_SetContext(context,`img`, Elem(P, `img`) inside tr); //|| select the first one context = NLUtil_SetContext(context,NLUtil_LastType(context), Select(NLUtil_LastSet(context),0,1)); //|| end loop loopResult = loopResult + [NLUtil_LastValue(context)]; end; NLUtil_SetContext(context, NLUtil_LastType(context), loopResult); if Size(OPTIONALARGS) == 0 then NLUtil_LastSet(context); else context; end;