From 2eff3ffb664d372d68ab2d953466d7ba946c96c2 Mon Sep 17 00:00:00 2001 From: default Date: Mon, 25 Nov 2024 10:08:50 +0100 Subject: [PATCH] Most CSV import code has been moved to their own functions. --- snac.h | 4 ++++ utils.c | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/snac.h b/snac.h index 7a262a9..9e00351 100644 --- a/snac.h +++ b/snac.h @@ -404,6 +404,10 @@ void verify_links(snac *user); void export_csv(snac *user); int migrate_account(snac *user); + +void import_blocked_accounts_csv(snac *user, const char *fn); +void import_following_accounts_csv(snac *user, const char *fn); +void import_list_csv(snac *user, const char *fn); void import_csv(snac *user); typedef enum { diff --git a/utils.c b/utils.c index 42200aa..b0d8193 100644 --- a/utils.c +++ b/utils.c @@ -670,13 +670,11 @@ void export_csv(snac *user) } -void import_csv(snac *user) -/* import CSV files from Mastodon */ +void import_blocked_accounts_csv(snac *user, const char *fn) +/* imports a Mastodon CSV file of blocked accounts */ { FILE *f; - const char *fn; - fn = "blocked_accounts.csv"; if ((f = fopen(fn, "r")) != NULL) { snac_log(user, xs_fmt("Importing from %s...", fn)); @@ -704,8 +702,14 @@ void import_csv(snac *user) } else snac_log(user, xs_fmt("Cannot open file %s", fn)); +} + + +void import_following_accounts_csv(snac *user, const char *fn) +/* imports a Mastodon CSV file of accounts to follow */ +{ + FILE *f; - fn = "following_accounts.csv"; if ((f = fopen(fn, "r")) != NULL) { snac_log(user, xs_fmt("Importing from %s...", fn)); @@ -757,8 +761,14 @@ void import_csv(snac *user) } else snac_log(user, xs_fmt("Cannot open file %s", fn)); +} + + +void import_list_csv(snac *user, const char *fn) +/* imports a Mastodon CSV file list */ +{ + FILE *f; - fn = "lists.csv"; if ((f = fopen(fn, "r")) != NULL) { snac_log(user, xs_fmt("Importing from %s...", fn)); @@ -808,6 +818,20 @@ void import_csv(snac *user) } else snac_log(user, xs_fmt("Cannot open file %s", fn)); +} + + +void import_csv(snac *user) +/* import CSV files from Mastodon */ +{ + FILE *f; + const char *fn; + + import_blocked_accounts_csv(user, "blocked_accounts.csv"); + + import_following_accounts_csv(user, "following_accounts.csv"); + + import_list_csv(user, "lists.csv"); fn = "bookmarks.csv"; if ((f = fopen(fn, "r")) != NULL) {