Libraryless. Click here for Pure Java version (5835L/36K).
persistable sclass Gazelle_GrabPostsLoop { S server = gazelle_server(); S _user, _botToken; Set<S> fields = litset("_modified", "text"); long changedAfter; double delay = 0.5; double errorDelay = 10; bool verbose, enabled = true; int pollFor = 600; // seconds for each poll bool firstGrab = true; !include #1028121 // setField + change() run { while licensed { pcall { if (enabled) grab(); } sleepSeconds(delay); } } void grab { O[] params = litobjectarray(+_user, +_botToken, fields := joinWithSpace(fields), +changedAfter, +pollFor); print(params := litorderedmap(params)); Map _result = cast postJSONPage(server + "bot/listPosts", params); if (verbose) print(+_result); S error = cast _result.get("error"); if (error != null) { print("Server ERROR: " + error); sleepSeconds(errorDelay); ret; } L<Map> posts = cast _result.get("result"); print("Found " + n2(posts, "new post")); L<GazellePost> posts2 = map(posts, p -> GazellePost(p)); for (GazellePost p : posts2) setField(changedAfter := max(changedAfter, p.modified)); if (nempty(posts2)) handlePosts(posts2); firstGrab = false; } swappable void handlePosts(Cl<GazellePost> posts) { for (GazellePost p : posts) pcall { handlePost(p); } } transient swappable void handlePost(GazellePost post) { } void reset { setField(changedAfter := 0L); } Cl<Long> allPostIDs() { Map _result = cast postJSONPage(server + "bot/listPosts", +_user, +_botToken); L<Map> posts = cast _result.get("result"); ret allToLong(collect id(posts)); } }
Began life as a copy of #1029982
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
Snippet ID: | #1029985 |
Snippet name: | Gazelle_GrabPostsLoop [OK] |
Eternal ID of this version: | #1029985/23 |
Text MD5: | 84a4d8d9d36f4e353ceb17d8ced2b741 |
Transpilation MD5: | 258fdf526af74d8665a90fd91b08a6a3 |
Author: | stefan |
Category: | javax / gazelle.rocks |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-06-28 22:06:03 |
Source code size: | 1780 bytes / 66 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 281 / 617 |
Version history: | 22 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |