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

36
LINES

< > BotCompany Repo | #1020385 // tbSearch_v2 - with standard classes + functions

JavaX fragment (include)

1  
static int tbSearch_v2_defaultMax = 3;
2  
static new ThreadLocal<Bool> tbSearch_v2_quick;
3  
static new ThreadLocal<S> tbSearch_v2_html;
4  
5  
static L<Snippet> tbSearch_v2(S query) {
6  
  ret tbSearch_v2(tbSearch_v2_defaultMax, query);
7  
}
8  
9  
static L<Snippet> tbSearch_v2(int max, S query) {
10  
  bool quick = isTrue(getAndClearThreadLocal(tbSearch_v2_quick));
11  
  S url = tb_mainServer() + "/tb/search.php?q=" + urlencode(query) + "&limit=" + max + "&quick=" + (quick ? 1 : 0) + standardCredentials();
12  
  ret tbSearch_v2_url(url);
13  
}
14  
    
15  
static L<Snippet> tbSearch_v2_url(S url) {
16  
  S page = loadPage(url);
17  
  if (eq(tbSearch_v2_html!, "want"))
18  
    tbSearch_v2_html.set(page);
19  
  new L<Snippet> results;
20  
  
21  
  Matcher m = Pattern.compile("<a href=\"http://code.botcompany.de/(\\d+)\"><b>(.*?)</b>").matcher(page);
22  
  while (m.find())
23  
    results.add(new Snippet(
24  
      fsI(m.group(1)),
25  
      htmldecode(dropTags(m.group(2))),
26  
      null));
27  
  
28  
  m = Pattern.compile(">(#\\d+)</a> - (.*?)<br>").matcher(page);
29  
30  
  while (m.find())
31  
    results.add(new Snippet(
32  
      m.group(1),
33  
      htmldecode(dropTags(m.group(2))),
34  
      null)); // no md5 for now
35  
  ret results;
36  
}

Author comment

Began life as a copy of #1003925

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1020385
Snippet name: tbSearch_v2 - with standard classes + functions
Eternal ID of this version: #1020385/7
Text MD5: b8599764acbad5fcd88d7bb59019d796
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-24 15:48:06
Source code size: 1173 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 273 / 320
Version history: 6 change(s)
Referenced in: [show references]