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

28
LINES

< > BotCompany Repo | #1003925 - tbSearch - searches snippets, returns ids and names

JavaX fragment (include)

static int tbSearch_defaultMax = 3;
static new ThreadLocal<Bool> tbSearch_quick;
static new ThreadLocal<S> tbSearch_html;

static L<Snippet> tbSearch(S query) {
  ret tbSearch(tbSearch_defaultMax, query);
}

static L<Snippet> tbSearch(int max, S query) {
  bool quick = isTrue(getAndClearThreadLocal(tbSearch_quick));
  S url = tb_mainServer() + "/tb/search.php?q=" + urlencode(query) + "&limit=" + max + (quick ? "&quick=1" : "") + standardCredentials();
  ret tbSearch_url(url);
}
    
static L<Snippet> tbSearch_url(S url) {
  S page = loadPage(url);
  if (eq(tbSearch_html!, "want"))
    tbSearch_html.set(page);
  Matcher m = Pattern.compile(">(#\\d+)</a> - (.*?)<br>").matcher(page);

  new L<Snippet> results;
  while (m.find())
    results.add(new Snippet(
      m.group(1),
      htmldecode(dropTags(m.group(2))),
      null)); // no md5 for now
  ret results;
}

Author comment

Began life as a copy of #1002569

download  show line numbers  debug dex   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1003925
Snippet name: tbSearch - searches snippets, returns ids and names
Eternal ID of this version: #1003925/6
Text MD5: 03fc186b679c1cd84038d51275f343b3
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-11-27 13:50:55
Source code size: 898 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 374 / 360
Version history: 5 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1003925 & http://1003925.tinybrain.de