Most CSV import code has been moved to their own functions.

This commit is contained in:
default 2024-11-25 10:08:50 +01:00
parent f549af8005
commit 2eff3ffb66
No known key found for this signature in database
2 changed files with 34 additions and 6 deletions

4
snac.h
View file

@ -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 {

36
utils.c
View file

@ -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) {