commit d11d037
default
·
2025-04-18 06:44:47 +0000 UTC
parent 8fbc8a3
New command-line options 'lists' and 'list_members'.
M
data.c
+13,
-0
1@@ -2340,6 +2340,19 @@ xs_val *list_maint(snac *user, const char *list, int op)
2 }
3
4 break;
5+
6+ case 4: /** find list id by name **/
7+ if (xs_is_string(list)) {
8+ xs *lol = list_maint(user, NULL, 0);
9+ const xs_list *li;
10+
11+ xs_list_foreach(lol, li) {
12+ if (strcmp(list, xs_list_get(li, 1)) == 0) {
13+ l = xs_dup(xs_list_get(li, 0));
14+ break;
15+ }
16+ }
17+ }
18 }
19
20 return l;
M
main.c
+34,
-0
1@@ -59,6 +59,8 @@ int usage(void)
2 printf("import_csv {basedir} {uid} Imports data from CSV files\n");
3 printf("import_list {basedir} {uid} {file} Imports a Mastodon CSV list file\n");
4 printf("import_block_list {basedir} {uid} {file} Imports a Mastodon CSV block list file\n");
5+ printf("lists {basedir} {uid} Returns the names of the lists created by the user\n");
6+ printf("list_members {basedir} {uid} {name} Returns the list of accounts inside a list\n");
7
8 return 1;
9 }
10@@ -282,9 +284,41 @@ int main(int argc, char *argv[])
11 return migrate_account(&snac);
12 }
13
14+ if (strcmp(cmd, "lists") == 0) { /** **/
15+ xs *lol = list_maint(&snac, NULL, 0);
16+ const xs_list *l;
17+
18+ xs_list_foreach(lol, l) {
19+ printf("%s (%s)\n", xs_list_get(l, 1), xs_list_get(l, 0));
20+ }
21+
22+ return 0;
23+ }
24+
25 if ((url = GET_ARGV()) == NULL)
26 return usage();
27
28+ if (strcmp(cmd, "list_members") == 0) { /** **/
29+ xs *lid = list_maint(&snac, url, 4);
30+
31+ if (lid != NULL) {
32+ xs *lcont = list_content(&snac, lid, NULL, 0);
33+ const char *md5;
34+
35+ xs_list_foreach(lcont, md5) {
36+ xs *actor = NULL;
37+
38+ if (valid_status(object_get_by_md5(md5, &actor))) {
39+ printf("%s (%s)\n", xs_dict_get(actor, "id"), xs_dict_get_def(actor, "preferredUsername", ""));
40+ }
41+ }
42+ }
43+ else
44+ fprintf(stderr, "Cannot find list named '%s'\n", url);
45+
46+ return 0;
47+ }
48+
49 if (strcmp(cmd, "alias") == 0) { /** **/
50 xs *actor = NULL;
51 xs *uid = NULL;