summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index e9ec251..c64829d 100644
--- a/utils.c
+++ b/utils.c
@@ -565,3 +565,64 @@ void verify_links(snac *user)
565 rename(bfn, fn); 565 rename(bfn, fn);
566 } 566 }
567} 567}
568
569
570void export_csv(snac *user)
571/* exports user data to current directory in a way that pleases Mastodon */
572{
573 FILE *f;
574 const char *fn;
575
576 fn = "bookmarks.csv";
577 if ((f = fopen(fn, "w")) != NULL) {
578 snac_log(user, xs_fmt("Creating %s...", fn));
579
580 xs *l = bookmark_list(user);
581 const char *md5;
582
583 xs_list_foreach(l, md5) {
584 xs *post = NULL;
585
586 if (valid_status(object_get_by_md5(md5, &post))) {
587 const char *id = xs_dict_get(post, "id");
588
589 if (xs_type(id) == XSTYPE_STRING)
590 fprintf(f, "%s\n", id);
591 }
592 }
593
594 fclose(f);
595 }
596 else
597 snac_log(user, xs_fmt("Cannot create file %s", fn));
598
599 fn = "blocked_accounts.csv";
600 if ((f = fopen(fn, "w")) != NULL) {
601 snac_log(user, xs_fmt("Creating %s...", fn));
602
603 xs *l = muted_list(user);
604 const char *actor;
605
606 xs_list_foreach(l, actor) {
607 xs *uid = NULL;
608 int status;
609
610 if (valid_status((status = webfinger_request(actor, NULL, &uid)))) {
611 fprintf(f, "%s\n", uid);
612 }
613 else
614 snac_log(user, xs_fmt("Error resolving muted user %s %d", actor, status));
615 }
616
617 fclose(f);
618 }
619 else
620 snac_log(user, xs_fmt("Cannot create file %s", fn));
621}
622
623
624void import_csv(snac *user)
625/* import CSV files from Mastodon */
626{
627 (void)user;
628}