1 | !636 |
2 | !standard functions |
3 | |
4 | !include #728 // JsonTok |
5 | |
6 | main {
|
7 | psvm {
|
8 | String id = args.length == 0 ? "#681" : args[0]; |
9 | String[] x = loadSnippetAndTitle(id); |
10 | System.out.println(x[0]); |
11 | System.out.println(x[1]); |
12 | } |
13 | |
14 | // for now, no caching... |
15 | static String[] loadSnippetAndTitle(String id) throws IOException {
|
16 | boolean debug = true; |
17 | long snippetID = parseSnippetID(id); |
18 | |
19 | String json; |
20 | try {
|
21 | URL url = new URL("http://tinybrain.de:8080/tb-int/get.php?id=" + snippetID + "&full=1");
|
22 | json = loadPage(url); |
23 | } catch (FileNotFoundException e) {
|
24 | throw new IOException("Snippet #" + snippetID + " not found or not public");
|
25 | } |
26 | |
27 | if (debug) |
28 | System.out.println("JSON [[" + json + "]]");
|
29 | Map<String, String> map = parseJsonObject(json); |
30 | return new String[] {map.get("text"), map.get("title")};
|
31 | } |
32 | |
33 | static Map<String, String> parseJsonObject(String s) {
|
34 | List<String> tok = JsonTok.split(s); |
35 | new (Tree)Map<String, String> map; |
36 | for (int i = 1; i+4 < tok.size(); i += 2) {
|
37 | if (tok.get(i+2).equals(":"))
|
38 | map.put(unquote(tok.get(i)), unquote(tok.get(i+4))); |
39 | } |
40 | return map; |
41 | } |
42 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000534 |
| Snippet name: | test loadSnippetAndTitle (developer platform) |
| Eternal ID of this version: | #1000534/1 |
| Text MD5: | 0d3fa26896ccefc18ba43ecfc0ed7246 |
| Author: | stefan |
| Category: | |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-10 23:58:40 |
| Source code size: | 1218 bytes / 42 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 911 / 849 |
| Referenced in: | [show references] |