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

40
LINES

< > BotCompany Repo | #1002589 // Call Number Maker Bot (ego4u.com) with cache

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

Libraryless. Click here for Pure Java version (1697L/11K/35K).

!752

static PersistentMap<S, S> cache;

p {
  cache = new PersistentMap("cache");
}

answer {
  if "spell *" exceptionToUser {
    S n = m.unq(0);
    if (isInteger(n)) {
      S val = cache.get(n);
      if (val != null) ret val;
      
      S html = loadPage("https://www.ego4u.com/en/cram-up/vocabulary/numbers/generator?param=" + n + "&show=Show");
      L<S> tok = htmlcoarsetok(html);
      int i = 0;
      while (i < l(tok) && !tok.get(i).startsWith("cardinal number "))
        i += 2;
      i = indexOf(tok, "<li>", i);
      
      if (i >= 0) {
        val = tok.get(i+1);
        cache.put(n, val);
        ret val;
      }
    }
  }
  
  if "fill spell numbers cache *" {
    int max = min(m.psi(0), 1000), made = 0;
    for (int i = 0; i < max; i++)
      if (cache.get(str(i)) == null) {
        askSelf("spell " + i);
        ++made;
      }
    ret "OK, made numbers up to " + max + " (" + made + " new). Cache size now: " + cache.size();
  }
}

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: #1002589
Snippet name: Call Number Maker Bot (ego4u.com) with cache
Eternal ID of this version: #1002589/1
Text MD5: 1e5bac9b38b27f3e3895f079f3e189fe
Transpilation MD5: c062e5c025c46bfab08e1363a43e46e8
Author: stefan
Category: eleu
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-03 17:40:50
Source code size: 1003 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 647 / 1008
Referenced in: [show references]