Libraryless. Click here for Pure Java version (3195L/22K/68K).
1 | !752 |
2 | |
3 | static O parser; |
4 | |
5 | // must be run together with sub-bot #1002185 (queries the |
6 | // slack slurper's database) |
7 | |
8 | static class SlackMsg { |
9 | S user, botName; // one of these is going to be set |
10 | S userName; // looked up if user != null |
11 | S type, text, ts; |
12 | O reactions; |
13 | S channelID; |
14 | } |
15 | |
16 | static PersistentMap<S, Tag> tagsByTS; |
17 | |
18 | static class Tag { |
19 | S parseResult; |
20 | } |
21 | |
22 | p { |
23 | tagsByTS = new PersistentMap("tagsByTS.log"); |
24 | } |
25 | |
26 | synchronized answer { |
27 | if match "get analysis for msg *" { |
28 | S msgID = m.unq(0); |
29 | Tag tag = tagsByTS.get(msgID); |
30 | if (tag == null) |
31 | ret "No analysis for that msg"; |
32 | else |
33 | ret structure(tag); |
34 | } |
35 | } |
36 | |
37 | static synchronized S html(S uri, Map<S, S> params) { |
38 | L<S> keepFields = litlist("channel", "n"); |
39 | |
40 | S channelName = formatChannelName(or(params.get("channel"), "talkingbots")); |
41 | O slurper = call(getMainBot(), "getBot", "#1002185"); |
42 | L log = cast call(slurper, "getLog", channelName); |
43 | |
44 | new L data; |
45 | int n; |
46 | if (!empty(params.get("n"))) |
47 | n = parseInt(params.get("n")); |
48 | else |
49 | n = max(0, l(log)-1)/100*100; |
50 | int n_end = min(n+100, l(log)); |
51 | |
52 | boolean analyze = !empty(params.get("analyze")); |
53 | |
54 | for (int i = n; i < n_end; i++) { |
55 | O o = log.get(i); |
56 | S ts = getString(o, "ts"); |
57 | Tag tag = tagsByTS.get(ts); |
58 | S text = cast get(o, "text"); |
59 | |
60 | if (analyze) { |
61 | tag = new Tag; |
62 | try { |
63 | tag.parseResult = nlparse(text); |
64 | } catch (Exception e) { |
65 | tag.parseResult = exceptionToUser(e); |
66 | } |
67 | tagsByTS.put(ts, tag); |
68 | } |
69 | |
70 | // make line and add to table |
71 | |
72 | Map map = htmlencode(litmap( |
73 | "Timestamp", ts, |
74 | "User", get(o, "userName"), |
75 | "Text", text, |
76 | "#", i+1, |
77 | "Parse Result", tag == null ? "-" : tag.parseResult |
78 | )); |
79 | |
80 | data.add(map); |
81 | } |
82 | |
83 | new StringBuilder buf; |
84 | S title = "Analyzing " + channelName; |
85 | buf.append(htag("title", title)); |
86 | buf.append(htag("h3", title)); |
87 | |
88 | // navigation |
89 | new L<S> l; |
90 | for (int i = 0; i < l(log); i += 100) |
91 | l.add(htag("a", str(i/100+1), "href", selfLink(params, keepFields, "n", str(i)))); |
92 | buf.append(htag("p", "Pages: " + join("\n", l))); |
93 | |
94 | S formContents = htmlTable(data, false); |
95 | formContents += htag("p", htag("input", "", "name", "analyze", "type", "submit", "value", "Re-analyze!")); |
96 | formContents += hiddenFields(params, keepFields); |
97 | buf.append(htag("form", formContents, "method", "POST")); |
98 | ret str(buf); |
99 | } |
100 | |
101 | static S nlparse(S text) { |
102 | if (parser == null) { |
103 | parser = hotwire_overBot("#1002369"); |
104 | call(getBot("#1002372"), "fillNLParser", parser); |
105 | } |
106 | |
107 | O result = call(parser, "parse", text); |
108 | ret structure(call(result, "explainLongestMatch")); |
109 | } |
Began life as a copy of #1002192
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: | #1002391 |
Snippet name: | Slack Analyzer (parses slack lines) |
Eternal ID of this version: | #1002391/1 |
Text MD5: | 7344e2b0c5022f03948687502ce0798e |
Transpilation MD5: | 8319bf5182dc1054eb29b6a61021bfcd |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-01-18 21:30:40 |
Source code size: | 2785 bytes / 109 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 646 / 15447 |
Referenced in: | [show references] |