Advertisement
uaa

iris.to nostr-my-profile-and-follows.json -> NostrFlu follower list converter

uaa
Feb 28th, 2023
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. // SPDX-License-Identifier: WTFPL
  2. // cc -Wall -O2 -I/usr/local/include -L/usr/local/lib -ljansson iris2flu.c -o iris2flu
  3.  
  4. #include <stdio.h>
  5. #include <jansson.h>
  6.  
  7. static void build_relay_list(json_t *content)
  8. {
  9. printf("# relays: %s\x0d\x0a", json_string_value(content));
  10. }
  11.  
  12. static void build_follow_list(json_t *tags)
  13. {
  14. int index;
  15. json_t *value;
  16.  
  17. json_array_foreach (tags, index, value) {
  18. if (*json_string_value(json_array_get(value, 0)) == 'p' &&
  19. json_string_length(json_array_get(value, 1))) {
  20. printf("%s\x0d\x0a",
  21. json_string_value(json_array_get(value, 1)));
  22. }
  23. }
  24. }
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28. json_t *root, *object, *tags, *content;
  29. json_error_t error;
  30.  
  31. if (argc < 2) {
  32. printf("usage: %s [filename]\n", argv[0]);
  33. goto fin0;
  34. }
  35.  
  36. if ((root = json_load_file(argv[1], 0, &error)) == NULL) {
  37. printf("file open error\n");
  38. goto fin0;
  39. }
  40.  
  41. // event object is inside array
  42. if ((object = json_array_get(root, 0)) == NULL) {
  43. printf("invalid JSON array\n");
  44. goto fin1;
  45. }
  46.  
  47. if (json_integer_value(json_object_get(object, "kind")) != 3 ||
  48. (content = json_object_get(object, "content")) == NULL ||
  49. (tags = json_object_get(object, "tags")) == NULL) {
  50. printf("invalid JSON content\n");
  51. goto fin1;
  52. }
  53.  
  54. build_relay_list(content);
  55. build_follow_list(tags);
  56.  
  57. fin1:
  58. json_decref(root);
  59. fin0:
  60. return 0;
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement