!636 !standard functions !include #728 // JsonTok main { psvm { String id = args.length == 0 ? "#681" : args[0]; String[] x = loadSnippetAndTitle(id); System.out.println(x[0]); System.out.println(x[1]); } // for now, no caching... static String[] loadSnippetAndTitle(String id) throws IOException { boolean debug = true; long snippetID = parseSnippetID(id); String json; try { URL url = new URL("http://tinybrain.de:8080/tb-int/get.php?id=" + snippetID + "&full=1"); json = loadPage(url); } catch (FileNotFoundException e) { throw new IOException("Snippet #" + snippetID + " not found or not public"); } if (debug) System.out.println("JSON [[" + json + "]]"); Map map = parseJsonObject(json); return new String[] {map.get("text"), map.get("title")}; } static Map parseJsonObject(String s) { List tok = JsonTok.split(s); new (Tree)Map map; for (int i = 1; i+4 < tok.size(); i += 2) { if (tok.get(i+2).equals(":")) map.put(unquote(tok.get(i)), unquote(tok.get(i+4))); } return map; } }