summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2025-06-19 19:19:08 +0200
committerGravatar grunfink2025-06-19 19:19:08 +0200
commita07458f408c304ae9d037c95bee77dbf4522f3f0 (patch)
tree702ba0dfdc34ae58c76d784f33f171d3523e2254
parentMinor tweak to usage screen. (diff)
downloadpenes-snac2-a07458f408c304ae9d037c95bee77dbf4522f3f0.tar.gz
penes-snac2-a07458f408c304ae9d037c95bee77dbf4522f3f0.tar.xz
penes-snac2-a07458f408c304ae9d037c95bee77dbf4522f3f0.zip
New command-line option export_posts.
-rw-r--r--main.c6
-rw-r--r--snac.h2
-rw-r--r--utils.c52
3 files changed, 60 insertions, 0 deletions
diff --git a/main.c b/main.c
index ddb02a8..f271abc 100644
--- a/main.c
+++ b/main.c
@@ -59,6 +59,7 @@ int usage(const char *cmd)
59 "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n" 59 "verify_links {basedir} {uid} Verifies a user's links (in the metadata)\n"
60 "search {basedir} {uid} {regex} Searches posts by content\n" 60 "search {basedir} {uid} {regex} Searches posts by content\n"
61 "export_csv {basedir} {uid} Exports followers, lists, MUTEd and bookmarks to CSV\n" 61 "export_csv {basedir} {uid} Exports followers, lists, MUTEd and bookmarks to CSV\n"
62 "export_posts {basedir} {iod} Exports all posts to outbox.json\n"
62 "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n" 63 "alias {basedir} {uid} {account} Sets account (@user@host or actor url) as an alias\n"
63 "migrate {basedir} {uid} Migrates to the account defined as the alias\n" 64 "migrate {basedir} {uid} Migrates to the account defined as the alias\n"
64 "import_csv {basedir} {uid} Imports data from CSV files\n" 65 "import_csv {basedir} {uid} Imports data from CSV files\n"
@@ -308,6 +309,11 @@ int main(int argc, char *argv[])
308 return 0; 309 return 0;
309 } 310 }
310 311
312 if (strcmp(cmd, "export_posts") == 0) { /** **/
313 export_posts(&snac);
314 return 0;
315 }
316
311 if (strcmp(cmd, "import_csv") == 0) { /** **/ 317 if (strcmp(cmd, "import_csv") == 0) { /** **/
312 import_csv(&snac); 318 import_csv(&snac);
313 return 0; 319 return 0;
diff --git a/snac.h b/snac.h
index 7f109e0..42fce87 100644
--- a/snac.h
+++ b/snac.h
@@ -434,6 +434,8 @@ void mastoapi_purge(void);
434void verify_links(snac *user); 434void verify_links(snac *user);
435 435
436void export_csv(snac *user); 436void export_csv(snac *user);
437void export_posts(snac *user);
438
437int migrate_account(snac *user); 439int migrate_account(snac *user);
438 440
439void import_blocked_accounts_csv(snac *user, const char *fn); 441void import_blocked_accounts_csv(snac *user, const char *fn);
diff --git a/utils.c b/utils.c
index 7adbce2..5367f22 100644
--- a/utils.c
+++ b/utils.c
@@ -725,6 +725,58 @@ void export_csv(snac *user)
725} 725}
726 726
727 727
728void export_posts(snac *user)
729/* exports all posts to an OrderedCollection */
730{
731 xs *ifn = xs_fmt("%s/public.idx", user->basedir);
732 xs *index = index_list(ifn, XS_ALL);
733 xs *ofn = xs_fmt("%s/export/outbox.json", user->basedir);
734 FILE *f;
735
736 if ((f = fopen(ofn, "w")) == NULL) {
737 snac_log(user, xs_fmt("Cannot create file %s", ofn));
738 return;
739 }
740
741 int cnt = 0;
742
743 /* raw output */
744 fprintf(f, "{\"@context\": \"https:/" "/www.w3.org/ns/activitystreams\",");
745 fprintf(f, "\"id\": \"outbox.json\",");
746 fprintf(f, "\"type\": \"OrderedCollection\",");
747 fprintf(f, "\"orderedItems\": [");
748
749 const char *md5;
750
751 snac_log(user, xs_fmt("Creating %s...", ofn));
752
753 xs_list_foreach(index, md5) {
754 xs *obj = NULL;
755
756 if (!valid_status(object_get_by_md5(md5, &obj)))
757 continue;
758
759 const char *type = xs_dict_get(obj, "type");
760
761 if (!xs_is_string(type) || strcmp(type, "Note"))
762 continue;
763
764 const char *atto = get_atto(obj);
765
766 if (!xs_is_string(atto) || strcmp(atto, user->actor))
767 continue;
768
769 xs *c_msg = msg_create(user, obj);
770 xs_json_dump(c_msg, 0, f);
771 cnt++;
772 }
773
774 fprintf(f, "], \"totalItems\": %d}", cnt);
775
776 fclose(f);
777}
778
779
728void import_blocked_accounts_csv(snac *user, const char *ifn) 780void import_blocked_accounts_csv(snac *user, const char *ifn)
729/* imports a Mastodon CSV file of blocked accounts */ 781/* imports a Mastodon CSV file of blocked accounts */
730{ 782{