Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

37
LINES

< > BotCompany Repo | #1002508 // Direct Google Search Bot [doesn't work anymore]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (5775L/41K/130K).

!752

p { bot(); }

static class GoogleResult {
  S unescapedUrl, cacheUrl, titleNoFormatting;
}

answer {
  if (matchStart("quickgoogle", s, m)) {
    S query = m.rest();
    S url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=" + urlencode(query);
    S json = loadPage(url);
    
    // json fumbling
    Map data = jsonDecodeMap(json);
    Map responseData =cast data.get("responseData");
    List<Map> _results = cast responseData.get("results");

    new L<GoogleResult> results;
    new StringBuilder buf;
    for (int i = 0; i < _results.size(); i++) {
      Map row = _results.get(i);
      //print(structure(row));
      new GoogleResult r;
      r.unescapedUrl = (S) row.get("unescapedUrl");
      r.cacheUrl = (S) row.get("cacheUrl");
      r.titleNoFormatting = htmldecode((S) row.get("titleNoFormatting"));
      results.add(r);
      //buf.append(r.titleNoFormatting + " [" + r.unescapedUrl + "]\n");
      buf.append(r.titleNoFormatting + "\n  " + r.unescapedUrl + "\n");
    }
    
    //ret structure(results);
    ret slackSnippet(buf);
  }
}

Author comment

Began life as a copy of #1000857

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002508
Snippet name: Direct Google Search Bot [doesn't work anymore]
Eternal ID of this version: #1002508/3
Text MD5: 54a0587b0109681a5858bdd6771a0d9a
Transpilation MD5: 57cf9c72aa7bdd5c90f28eb09ce59672
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-16 00:38:21
Source code size: 1116 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 641 / 1184
Version history: 2 change(s)
Referenced in: [show references]