Source: site.view [edit]
Function name: testDocument
Arguments:
Description: Test columns and do error reporting
Page type: webl
Render function:  
Module: perfectCartoon

Page source:

   var fi = Wub_GetFunctionInfo("cartoonDBSettings");
   var settings = WubEval(fi.exec);
   
// Try it three times to increase robustness?
   var P = GetURL(settings.dbUrl, nil, nil, [. mimetype="text/plain", autoredirect=true .]);

   var URL=0;
   var IMG=1;
   var CAPTION=2;
   var AUTHOR=3;
   var TAGS=4;
   var SCORE=5;
   var FRTAGS=6;
   var FRTEXT=7;

   var cln3 = fun(s)
      s = ExpandCharEntities(Str_Trim(s));
      var GOODCHARS = "abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ-'1234567890";
      var i = 0;
      var r = "";
      while i < Size(s) do
         var c = Select(s, i, i+1);
         if (Str_IndexOf(c, GOODCHARS) >= 0) then
            r = r + c
         end;
         i = i + 1
      end;
      return r
   end;

   var cln2 = fun(s)
      s = ExpandCharEntities(Str_Trim(s));
      s = Wub_ReplaceAll(s, "/>", "");
      s = Wub_ReplaceAll(s, "\t", " ");
      s = Wub_ReplaceAll(s, "\\", "");
      s = Wub_ReplaceAll(s, `"`, "'");
      s = Wub_ReplaceAll(s, "???", "");
      s = Wub_ReplaceAll(s, "??", "");
      // s = Wub_ReplaceAll(s, ",", " ");
      return s;
   end;
  
   var cln = fun(s)
      return cln2(s);
   end;
   
   var res = "";
   var good = 0;
   var bad = 0;

   var trs = Str_Split(Markup(P), "\n");
   every tr in trs do
     var dir = tr.dir ? nil;
     var tds = Str_Split(tr, "\t");
   
     if Size(tds) > 5 then // (dir == "ltr") then
   
        var fImg = Str_ToLowerCase(cln(tds[IMG])) ? "";
        var fPageUrl = Str_ToLowerCase(cln(tds[URL])) ? "";
        var fCaption = cln(tds[CAPTION]) ? "";
        var fAuthor = cln(tds[AUTHOR]) ? "";
        var fTags = cln(tds[TAGS]) ? "";
        var fScore = ToInt(cln(tds[SCORE])) ? "";
        var fCaptionFr = cln(tds[FRTEXT]) ? "";
        var fTagsFr = cln(tds[FRTAGS]) ? "";
     
        if fPageUrl == "siteurl" and fImg == "imgurl" then
           var nop = 0
        elsif (!Str_StartsWith(fImg, "http")) then
           res = res + "No http for img (" + fImg + "):\n" + tr + "-----\n";
           bad = bad + 1
        elsif (!Str_StartsWith(fPageUrl, "http")) then
           res = res + "No http for page url (" + fPageUrl + "):\n" + tr + "-----\n";
           bad = bad + 1
        elsif (fScore == "") then
           res = res + "No score boost found:\n" + tr + "-----\n";
           bad = bad + 1
        else
           good = good + 1
        end
     
     elsif Str_Trim(tr) == "" then
        var nop = 0
     else
        res = res + "Less than 6 columns:\n" + tr + "-----\n";
        bad = bad + 1
     end
   end;       
     
   "Good: " + ToString(good) + "\n" +
   "Bad: " + ToString(bad) + "\n" +
   res