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: 649 / 1011
Referenced in: #3000201 - Answer for stefanreich (>> list all files)
#3000202 - Answer for stefanreich (>> T conversion bot)
#3000203 - Answer for stefanreich (>> timing hello bot)
#3000208 - Answer for bgrgndz (>> list sub bots)
#3000209 - Answer for bgrgndz (>> list sub bots)
#3000238 - Answer for stefanreich (>> t power bot)
#3000369 - Answer for Stefan (>> list sub bots)
#3000376 - Answer for stefanreich (>> list sub bots)
#3000377 - Answer for stefanreich (>> timing eleu?)
#3000380 - Answer for stefanreich (>> list sub bots)
#3000381 - Answer for speedforce (>> list sub bots)
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)