mirror of https://codeberg.org/cage/tinmop/
- prompted for older threshold instead of using a constant.
This commit is contained in:
parent
bce702465c
commit
3b7cc47c8f
|
@ -25,11 +25,11 @@
|
||||||
|
|
||||||
(in-package :scripts)
|
(in-package :scripts)
|
||||||
|
|
||||||
(define-constant +min-past-date+ "2021-08-01" :test #'string=)
|
(defparameter *min-past-date* nil)
|
||||||
|
|
||||||
(defparameter *date-delete-treshold* "2021-10-01")
|
(defparameter *date-delete-treshold* nil)
|
||||||
|
|
||||||
(defun decode-date (post)
|
(defun decode-post-date (post)
|
||||||
(multiple-value-bind (x y z day month year)
|
(multiple-value-bind (x y z day month year)
|
||||||
(decode-universal-time (tooter:created-at post) 0)
|
(decode-universal-time (tooter:created-at post) 0)
|
||||||
(declare (ignore x y z))
|
(declare (ignore x y z))
|
||||||
|
@ -44,19 +44,20 @@
|
||||||
(string< a b))
|
(string< a b))
|
||||||
|
|
||||||
(defun list-posts (min-past-date show-progress &optional (max-id nil) (accum ()))
|
(defun list-posts (min-past-date show-progress &optional (max-id nil) (accum ()))
|
||||||
(let* ((username (swconf:config-username))
|
(let* ((username (swconf:config-username))
|
||||||
(user-id (db:acct->id username))
|
(user-id (db:acct->id username))
|
||||||
(posts (api-client:get-timeline (ui::timeline->kind db:+home-timeline+)
|
(timeline-type (ui::timeline->kind db:+home-timeline+))
|
||||||
:local t
|
(posts (api-client:get-timeline timeline-type
|
||||||
:max-id max-id
|
:local t
|
||||||
:limit 10))
|
:max-id max-id
|
||||||
(sorted-posts (api-client:sort-id< posts))
|
:limit 10))
|
||||||
(min-post-id (tooter:id (first sorted-posts)))
|
(sorted-posts (api-client:sort-id< posts))
|
||||||
(min-post-date (decode-date (first sorted-posts)))
|
(min-post-id (tooter:id (first sorted-posts)))
|
||||||
(my-posts (remove-if-not (lambda (a)
|
(min-post-date (decode-post-date (first sorted-posts)))
|
||||||
(string= (tooter:id (tooter:account a))
|
(my-posts (remove-if-not (lambda (a)
|
||||||
user-id))
|
(string= (tooter:id (tooter:account a))
|
||||||
posts)))
|
user-id))
|
||||||
|
posts)))
|
||||||
(if (and posts
|
(if (and posts
|
||||||
(date>= min-post-date min-past-date))
|
(date>= min-post-date min-past-date))
|
||||||
(progn
|
(progn
|
||||||
|
@ -70,18 +71,37 @@
|
||||||
(client:authorize)
|
(client:authorize)
|
||||||
(format t "This client has been authorized.~%")
|
(format t "This client has been authorized.~%")
|
||||||
(format t "Please provide the post's maximum creation date.~%")
|
(format t "Please provide the post's maximum creation date.~%")
|
||||||
(format t "Posts with date older then the provided one will be deleted~%")
|
(format t "Posts with date older than the provided one will be deleted~%")
|
||||||
(write-string "Maximum date (format \"YYY-MM-DD\"): ")
|
(write-string "Maximum date (format \"YYY-MM-DD\"): ")
|
||||||
(finish-output)
|
(finish-output)
|
||||||
(let* ((input-date (read-line))
|
(let* ((input-date (read-line))
|
||||||
(*date-delete-treshold* (db-utils:encode-datetime-string input-date)))
|
(*date-delete-treshold* (db-utils:encode-datetime-string input-date)))
|
||||||
(when (yes-or-no-p "deleting posts older than ~s. Continue?" input-date)
|
(format t "Please provide the post's minimum creation date.~%")
|
||||||
(if *date-delete-treshold*
|
(format t "Posts with date older than the provided one will *not* be deleted~%")
|
||||||
(let ((posts (list-posts +min-past-date+ t)))
|
(write-string "Minimum date (format \"YYY-MM-DD\"): ")
|
||||||
(loop for post in posts when (date< (decode-date post) *date-delete-treshold*) do
|
(finish-output)
|
||||||
(let ((post-contents (with-output-to-string (stream) (tooter::present post stream))))
|
(let* ((min-input-date (read-line))
|
||||||
(format t "deleting~2%~a~%" post-contents)
|
(*min-past-date* (db-utils:encode-datetime-string min-input-date)))
|
||||||
(api-client:delete-status (tooter:id post))))))
|
(when (yes-or-no-p "Deleting posts older than ~s and newer than ~s. Continue?"
|
||||||
(format *error-output* "Date ~s is not valid, exiting.~%" input-date)))))
|
input-date
|
||||||
|
min-input-date)
|
||||||
|
(cond
|
||||||
|
((null *date-delete-treshold*)
|
||||||
|
(format *error-output* "Date ~s is not valid, exiting.~%" input-date))
|
||||||
|
((null *min-past-date*)
|
||||||
|
(format *error-output* "Date ~s is not valid, exiting.~%" min-input-date))
|
||||||
|
(t
|
||||||
|
(let ((posts (list-posts (db-utils:decode-date-string *min-past-date*) t)))
|
||||||
|
(format t "Start deleting...~%")
|
||||||
|
(loop for post in posts
|
||||||
|
when (date< (decode-post-date post)
|
||||||
|
(db-utils:decode-date-string *date-delete-treshold*))
|
||||||
|
do
|
||||||
|
(let ((post-contents (with-output-to-string (stream)
|
||||||
|
(tooter::present post stream))))
|
||||||
|
(format t "deleting~2%~a~%" post-contents))))))))))
|
||||||
|
|
||||||
|
; (api-client:delete-status (tooter:id post)))))))))))
|
||||||
|
|
||||||
|
|
||||||
(main)
|
(main)
|
||||||
|
|
Loading…
Reference in New Issue