Libraryless. Click here for Pure Java version (1549L/10K/36K).
1 | !747 |
2 | |
3 | m { |
4 | static new Map<S, S> entries; |
5 | |
6 | static S pattern = "meta * - just got it from the web. snippet * now has md5 * and title *."; |
7 | |
8 | p { |
9 | readLocally("entries"); |
10 | print(entries.size() + " entries in cache."); |
11 | makeAndroid("Snippet Cache Bot. v2."); |
12 | } |
13 | |
14 | static void addEntry(S e) { |
15 | entries.put(extractID(e), e); // TODO: compare timestamps |
16 | saveLocally("entries"); |
17 | } |
18 | |
19 | static S getEntry(S roughID) { |
20 | S id = formatSnippetID(unquote(roughID)); |
21 | S e = entries.get(id); |
22 | if (e == null) { |
23 | // Load from web! |
24 | S title = getSnippetTitle(id); |
25 | S md5 = getSnippetMD5(id); |
26 | e = "meta " + quote(now()) + " - just got it from the web. snippet " + quote(id) + " now has md5 " + quote(md5) + " and title " + quote(title) + "."; |
27 | addEntry(e); |
28 | } |
29 | return e; |
30 | } |
31 | |
32 | static S extractID(S e) { |
33 | new Matches m; |
34 | if (!find3("snippet *", e, m)) |
35 | return null; |
36 | return formatSnippetID(unquote(m.m[0])); |
37 | } |
38 | |
39 | static S extractMD5(S e) { |
40 | new Matches m; |
41 | if (!find3("md5 *", e, m)) |
42 | return null; |
43 | return unquote(m.m[0]); |
44 | } |
45 | |
46 | static S extractTitle(S e) { |
47 | new Matches m; |
48 | if (!find3("title *", e, m)) |
49 | return null; |
50 | return unquote(m.m[0]); |
51 | } |
52 | |
53 | static synchronized S answer(S s) { |
54 | new Matches m; |
55 | |
56 | // put new information in store |
57 | |
58 | if (match3(pattern, s, m)) { |
59 | print("New entry: " + structure(m.m)); |
60 | addEntry(s); |
61 | return "OK, stored."; |
62 | } |
63 | |
64 | // retrieve information |
65 | |
66 | if (match3("get md5 of snippet *", s, m)) |
67 | return extractMD5(getEntry(m.m[0])); |
68 | |
69 | if (match3("get title of snippet *", s, m)) { |
70 | return extractTitle(getEntry(m.m[0])); |
71 | } |
72 | |
73 | // other commands |
74 | |
75 | if (match3("please consolidate", s, m)) |
76 | return "OK, nothing to consolidate."; |
77 | |
78 | return null; |
79 | } |
80 | } |
Began life as a copy of #1001216
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001237 |
Snippet name: | Snippet Cache Bot v2 |
Eternal ID of this version: | #1001237/1 |
Text MD5: | 6cb3d4237cc2537a7767e9ef26041415 |
Transpilation MD5: | 206e25e33be374684cf844834f34475d |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-10-04 15:04:39 |
Source code size: | 1940 bytes / 80 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 585 / 672 |
Referenced in: | [show references] |