diff options
| -rw-r--r-- | data.c | 23 | ||||
| -rw-r--r-- | main.c | 5 | ||||
| -rw-r--r-- | snac.h | 3 | ||||
| -rw-r--r-- | utils.c | 61 |
4 files changed, 92 insertions, 0 deletions
| @@ -1574,6 +1574,29 @@ int is_muted(snac *snac, const char *actor) | |||
| 1574 | } | 1574 | } |
| 1575 | 1575 | ||
| 1576 | 1576 | ||
| 1577 | xs_list *muted_list(snac *user) | ||
| 1578 | /* returns the list (actor URLs) of the muted morons */ | ||
| 1579 | { | ||
| 1580 | xs_list *l = xs_list_new(); | ||
| 1581 | xs *spec = xs_fmt("%s/muted/" "*", user->basedir); | ||
| 1582 | xs *files = xs_glob(spec, 0, 0); | ||
| 1583 | const char *fn; | ||
| 1584 | |||
| 1585 | xs_list_foreach(files, fn) { | ||
| 1586 | FILE *f; | ||
| 1587 | |||
| 1588 | if ((f = fopen(fn, "r")) != NULL) { | ||
| 1589 | xs *actor = xs_strip_i(xs_readline(f)); | ||
| 1590 | fclose(f); | ||
| 1591 | |||
| 1592 | l = xs_list_append(l, actor); | ||
| 1593 | } | ||
| 1594 | } | ||
| 1595 | |||
| 1596 | return l; | ||
| 1597 | } | ||
| 1598 | |||
| 1599 | |||
| 1577 | /** bookmarking **/ | 1600 | /** bookmarking **/ |
| 1578 | 1601 | ||
| 1579 | int is_bookmarked(snac *user, const char *id) | 1602 | int is_bookmarked(snac *user, const char *id) |
| @@ -267,6 +267,11 @@ int main(int argc, char *argv[]) | |||
| 267 | return 0; | 267 | return 0; |
| 268 | } | 268 | } |
| 269 | 269 | ||
| 270 | if (strcmp(cmd, "export_csv") == 0) { /** **/ | ||
| 271 | export_csv(&snac); | ||
| 272 | return 0; | ||
| 273 | } | ||
| 274 | |||
| 270 | if ((url = GET_ARGV()) == NULL) | 275 | if ((url = GET_ARGV()) == NULL) |
| 271 | return usage(); | 276 | return usage(); |
| 272 | 277 | ||
| @@ -165,6 +165,7 @@ xs_list *following_list(snac *snac); | |||
| 165 | void mute(snac *snac, const char *actor); | 165 | void mute(snac *snac, const char *actor); |
| 166 | void unmute(snac *snac, const char *actor); | 166 | void unmute(snac *snac, const char *actor); |
| 167 | int is_muted(snac *snac, const char *actor); | 167 | int is_muted(snac *snac, const char *actor); |
| 168 | xs_list *muted_list(snac *user); | ||
| 168 | 169 | ||
| 169 | int is_bookmarked(snac *user, const char *id); | 170 | int is_bookmarked(snac *user, const char *id); |
| 170 | int bookmark(snac *user, const char *id); | 171 | int bookmark(snac *user, const char *id); |
| @@ -387,6 +388,8 @@ void mastoapi_purge(void); | |||
| 387 | 388 | ||
| 388 | void verify_links(snac *user); | 389 | void verify_links(snac *user); |
| 389 | 390 | ||
| 391 | void export_csv(snac *user); | ||
| 392 | void import_csv(snac *user); | ||
| 390 | 393 | ||
| 391 | typedef enum { | 394 | typedef enum { |
| 392 | #define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code, | 395 | #define HTTP_STATUS(code, name, text) HTTP_STATUS_ ## name = code, |
| @@ -565,3 +565,64 @@ void verify_links(snac *user) | |||
| 565 | rename(bfn, fn); | 565 | rename(bfn, fn); |
| 566 | } | 566 | } |
| 567 | } | 567 | } |
| 568 | |||
| 569 | |||
| 570 | void 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 | |||
| 624 | void import_csv(snac *user) | ||
| 625 | /* import CSV files from Mastodon */ | ||
| 626 | { | ||
| 627 | (void)user; | ||
| 628 | } | ||