From 4b649d91ae8546310ca6bbcefb47bb779da7a9c5 Mon Sep 17 00:00:00 2001 From: cage Date: Sun, 14 Nov 2021 13:44:58 +0100 Subject: [PATCH] - added a script to get a list of people user is following. --- scripts/get-following.lisp | 40 ++++++++++++++++++++++++++++++++++++++ src/api-client.lisp | 2 +- src/api-pleroma.lisp | 24 +++++++++++++++++++++++ src/package.lisp | 3 ++- 4 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 scripts/get-following.lisp diff --git a/scripts/get-following.lisp b/scripts/get-following.lisp new file mode 100644 index 0000000..6b8289e --- /dev/null +++ b/scripts/get-following.lisp @@ -0,0 +1,40 @@ +;; geat a list of people you are following +;; Copyright © 2021 cage + +;; This program is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;; usage: + +;; after configuring tinmop (https://www.autistici.org/interzona/tinmop.html) +;; tinmop -e get-following.lisp > follows.csv + +(in-package :scripts) + +(defun connect () + (client:init) + (client:authorize)) + +(defun main () + (connect) + (db-utils:with-ready-database (:connect t) + (let* ((username (db:acct->id (swconf:config-username))) + (local-server-name (swconf:config-server-name)) + (follows-accounts (api-pleroma:get-following username))) + (loop for account in follows-accounts do + (let ((acct (tooter:account-name account))) + (if (scan "@" acct) + (format t "~s~%" acct) + (format t "\"~a@~a\"~%" acct local-server-name))))))) + +(main) diff --git a/src/api-client.lisp b/src/api-client.lisp index 1348f47..87e548c 100644 --- a/src/api-client.lisp +++ b/src/api-client.lisp @@ -511,7 +511,7 @@ database." (tooter:unfollow *client* user-id)) (defun-api-call follow-requests () - "Gets the request tio follow the user of this client" + "Gets the request to follow the user of this client" (let ((requests (tooter:follow-requests *client*))) (values requests (mapcar #'tooter:account-name requests)))) diff --git a/src/api-pleroma.lisp b/src/api-pleroma.lisp index 583e97b..f515fc0 100644 --- a/src/api-pleroma.lisp +++ b/src/api-pleroma.lisp @@ -117,5 +117,29 @@ media `media'. Returns a `chat-message' instance" (api-pleroma:post-chat-message api-client:*client* chat-id nil message) (api-pleroma:post-chat-message api-client:*client* chat-id message nil))) +(defmethod get-following-accounts ((client tooter:client) (id string) + &key + (max-id nil) + (min-id nil) + (since-id nil) + (limit 10) + (offset 0)) + (decode-account (tooter:query client + (format nil "/api/v1/accounts/~a/following" id) + :max-id max-id + :min-id min-id + :since-id since-id + :limit limit + :offset offset))) + (api-client:defun-api-call create-new-chat (user-id) (create-chat api-client:*client* user-id)) + +(api-client:defun-api-call get-following (user-id &optional (min-id nil) (accum '())) + "Get a list of accounts that user is following" + (let ((partial (api-client:sort-id< (get-following-accounts api-client:*client* + user-id + :max-id min-id)))) + (if partial + (get-following user-id (tooter:id (first partial)) (append partial accum)) + accum))) diff --git a/src/package.lisp b/src/package.lisp index 5396de7..2757066 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1545,7 +1545,8 @@ :get-chat-messages :get-chats :post-on-chat - :create-new-chat)) + :create-new-chat + :get-following)) (defpackage :api-client (:use