1 | sclass Text { |
2 | S title; |
3 | new L<S> lines; |
4 | } |
5 | |
6 | static L<Text> loadPoems() { |
7 | new L<Text> texts; |
8 | |
9 | L<Snippet> snippets = listSnippetsOfType(48); // "Natural Language" |
10 | |
11 | for (Snippet sn : snippets) pcall { |
12 | if (parseSnippetID(sn.id) < 1003000) break; |
13 | texts.addAll(loadPoems(sn.id)); |
14 | } |
15 | |
16 | print("Got " + n(l(texts), "text") + " (" + structure(collect(texts, "title")) + ")"); |
17 | ret texts; |
18 | } |
19 | |
20 | static L<Text> loadPoems(S snippetID) { |
21 | new L<Text> texts; |
22 | |
23 | L<S> lines = toLinesFullTrim(loadSnippet(snippetID)); |
24 | |
25 | int i = 0; |
26 | while (i < l(lines)) { |
27 | new Text text; |
28 | |
29 | // title |
30 | if (i+1 < l(lines) && lines.get(i+1).startsWith("-")) { |
31 | text.title = lines.get(i); |
32 | i += 2; |
33 | } else |
34 | text.title = ""; |
35 | |
36 | // text |
37 | while (i < l(lines) && |
38 | (i+1 >= l(lines) || !lines.get(i+1).startsWith("-"))) |
39 | text.lines.add(lines.get(i++)); |
40 | texts.add(text); |
41 | } |
42 | |
43 | ret texts; |
44 | } |
Began life as a copy of #1003053
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, iveijnkanddl, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003061 |
Snippet name: | loadPoems - load all poems from website |
Eternal ID of this version: | #1003061/1 |
Text MD5: | bc413ff1ba4317c94efaacf8091c09a9 |
Author: | stefan |
Category: | eleu / nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-05-31 00:40:58 |
Source code size: | 968 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 709 / 1049 |
Referenced in: | [show references] |