From 21a40347107cbf9aab52887258e80095fe429387 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sat, 13 May 2023 22:47:10 -0700 Subject: [PATCH] successfully posts --- insta-feed.py | 13 +++++++++++++ insta2toot.asd | 4 ++++ insta2toot.lisp | 36 ++++++++++++++++++++++++++++++++++++ instapass | 1 + 4 files changed, 54 insertions(+) create mode 100644 insta-feed.py create mode 100644 insta2toot.asd create mode 100644 insta2toot.lisp create mode 100644 instapass diff --git a/insta-feed.py b/insta-feed.py new file mode 100644 index 0000000..ab60fa2 --- /dev/null +++ b/insta-feed.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + +import instaloader + +from datetime import datetime +from datetime import timedelta + +SINCE = datetime.now()-timedelta(hours=1) + +L = instaloader.Instaloader() + +L.load_session_from_file('2001beam') +posts=L.download_feed_posts(max_count=20, fast_update=True, post_filter = ( lambda p: p.date > SINCE )) diff --git a/insta2toot.asd b/insta2toot.asd new file mode 100644 index 0000000..d6f4ff0 --- /dev/null +++ b/insta2toot.asd @@ -0,0 +1,4 @@ +(asdf:defsystem "insta2toot" + :version "0.1" + :depends-on ("uiop" "local-time" "bordeaux-threads" "tooter" "cl-ppcre" "cl-json") + :components ((:file "insta2toot"))) diff --git a/insta2toot.lisp b/insta2toot.lisp new file mode 100644 index 0000000..23b6dd4 --- /dev/null +++ b/insta2toot.lisp @@ -0,0 +1,36 @@ +(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)) diff --git a/instapass b/instapass new file mode 100644 index 0000000..c94ba74 --- /dev/null +++ b/instapass @@ -0,0 +1 @@ ++}]B~Q?'O6\$I