sclass Text {
S title;
new L<S> lines;
}
static L<Text> loadPoems() {
new L<Text> texts;
L<Snippet> snippets = listSnippetsOfType(48); // "Natural Language"
for (Snippet sn : snippets) pcall {
if (parseSnippetID(sn.id) < 1003000) break;
texts.addAll(loadPoems(sn.id));
}
print("Got " + n(l(texts), "text") + " (" + structure(collect(texts, "title")) + ")");
ret texts;
}
static L<Text> loadPoems(S snippetID) {
new L<Text> texts;
L<S> lines = toLinesFullTrim(loadSnippet(snippetID));
int i = 0;
while (i < l(lines)) {
new Text text;
// title
if (i+1 < l(lines) && lines.get(i+1).startsWith("-")) {
text.title = lines.get(i);
i += 2;
} else
text.title = "";
// text
while (i < l(lines) &&
(i+1 >= l(lines) || !lines.get(i+1).startsWith("-")))
text.lines.add(lines.get(i++));
texts.add(text);
}
ret texts;
}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: | 1208 / 1513 |
| Referenced in: | #1003210 - loadPoem - load one poem from snippet #1006654 - Standard functions list 2 (LIVE, continuation of #761) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |