37 lines
2.0 KiB
Common Lisp
37 lines
2.0 KiB
Common Lisp
(defvar *client* (make-instance 'tooter:client
|
|
:base "https://pleroma.1of444.top"
|
|
:name "insta2toot"))
|
|
|
|
(tooter:authorize *client*)
|
|
(tooter:authorize *client* "I-kv18ow8ObPmODRetrZ6g58YZp6Fvz4b_SOTzvx17M")
|
|
(tooter:account *client*)
|
|
|
|
(uiop:run-program '("rm" "-rf" ":feed"))
|
|
(uiop:run-program '("instaloader" "-l" "2001beam" ) :input "instapass" :output t)
|
|
(uiop:run-program '("python" "insta-feed.py") :output t)
|
|
|
|
(defun get-post-prefixes ()
|
|
(loop for file in (uiop:directory-files ":feed")
|
|
if (cl-ppcre:scan "json.xz$" (uiop:unix-namestring file))
|
|
collect (subseq (uiop:unix-namestring file) 0 (- (length (uiop:unix-namestring file))
|
|
(length ".json.xz")))))
|
|
(defun repost-post (post-prefix)
|
|
(let* ((json-file (concatenate 'string post-prefix ".json.xz"))
|
|
(post-json (uiop:run-program `("xzcat" ,json-file) :output :string))
|
|
(post-metadata (with-input-from-string (s post-json) ( cl-json:decode-json s)))
|
|
(post-user (cdr (assoc :username (cdr (assoc :owner (cdr (assoc :node post-metadata)))))))
|
|
(post-desc (or (cdr (assoc :text (cdr (assoc :node (car (cdr (assoc :edges (cdr (assoc :edge--media--to--caption (cdr (assoc :node post-metadata))))))))))) ""))
|
|
(post-files (loop for file in (uiop:directory-files ":feed")
|
|
if (and (cl-ppcre:scan post-prefix (uiop:unix-namestring file))
|
|
(cl-ppcre:scan "(jpg$)|(png$)|(mp4$)" (uiop:unix-namestring file)))
|
|
collect file))
|
|
(medias (mapcar (lambda (x) (tooter:make-media *client* x))
|
|
(subseq post-files 0 (min (length post-files) 4)))))
|
|
(tooter:make-status *client*
|
|
(format nil "~a
|
|
-~a via instagram" post-desc post-user)
|
|
:media medias)))
|
|
|
|
(loop for post-prefix in (get-post-prefixes)
|
|
collect (repost-post post-prefix))
|