Uses 911K of libraries. Click here for Pure Java version (11407L/63K).
1 | !7 |
2 | |
3 | cmodule Google { |
4 | S query; |
5 | L<SS> result; |
6 | switchable S language = "lang_en"; |
7 | |
8 | transient int maxInputLength = 120; |
9 | transient NotTooOften notTooOften = onlyEvery10Secs(); |
10 | transient WaitForStableValue<S> waitForStableValue = new(5.0); |
11 | transient volatile bool calculating; |
12 | transient JTable table; |
13 | transient SimpleLiveValue<S> lvQuery = stringLiveValue(); |
14 | |
15 | visual jLiveValueSection(lvQuery, dataToTable_uneditable(result, table = sexyTable())); |
16 | |
17 | void unvisualize() { table = null; } |
18 | |
19 | start { |
20 | lvQuery.set(query); |
21 | ownTimer(doEvery(1000, r updateMe)); |
22 | } |
23 | |
24 | void update { |
25 | S s = dm_getInterestingString(); |
26 | if (nempty(s) && l(s) <= maxInputLength) { // TODO: more quality checks? |
27 | waitForStableValue.set(s); |
28 | } |
29 | |
30 | fS q = waitForStableValue!; |
31 | if (nempty(q) && neq(q, query) && allowedToGoogleSomething()) |
32 | dm_q(r { calc(q) }); |
33 | } |
34 | |
35 | void calc(S q) { |
36 | if (eq(query, q)) ret; |
37 | query = q; result = null; |
38 | lvQuery.set(q); |
39 | temp tempSetField(this, calculating := true); |
40 | L<T3S> l = quickGoogle2(q, language); |
41 | result = map(l, func(T3S t) -> SS { |
42 | litorderedmap("Result" := second(t), "Desc" := nullOnEmpty(third(t)), "Link" := first(t)) |
43 | }); |
44 | dataToTable_uneditable_ifHasTable(result, table); |
45 | } |
46 | |
47 | bool allowedToGoogleSomething() { |
48 | ret notTooOften.canDoAgain_willDoIfTrue(); |
49 | } |
50 | } |
Began life as a copy of #1015833
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vpdwwinrgdga
No comments. add comment
Snippet ID: | #1015891 |
Snippet name: | Google Search (Dyn Module v2, OK) |
Eternal ID of this version: | #1015891/18 |
Text MD5: | 317e223faea3ea1793093124488431b8 |
Transpilation MD5: | fb0b2f1adec7621a6a4bf1f2087a8a5b |
Author: | stefan |
Category: | |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-06-03 16:09:08 |
Source code size: | 1427 bytes / 50 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 604 / 60993 |
Version history: | 17 change(s) |
Referenced in: | [show references] |