fix mastodon fetch issues

This commit is contained in:
Travis Shears 2025-08-08 23:27:04 +02:00
parent ded5314125
commit 8263c09b50
3 changed files with 14 additions and 14 deletions

View file

@ -33,6 +33,7 @@ $ java -jar ./target/micro-blog-standalone.jar
Build new docker image and push it to ECR Build new docker image and push it to ECR
```shell ```shell
$ export AWS_PROFILE=personal
$ docker buildx build --platform linux/amd64,linux/arm64 -t 853019563312.dkr.ecr.eu-central-1.amazonaws.com/micro-blog-fetchers-homelabstack:latest --push . $ docker buildx build --platform linux/amd64,linux/arm64 -t 853019563312.dkr.ecr.eu-central-1.amazonaws.com/micro-blog-fetchers-homelabstack:latest --push .
``` ```

View file

@ -20,24 +20,23 @@
(defn get-posts-until-id [id] (defn get-posts-until-id [id]
(let [limit 10 (let [limit 10
posts url (str (@config :mastodon-host) "/api/v1/accounts/" (@config :mastodon-account-id) "/statuses")]
(tel/log! {:level :info :data {:url url :post-id id}} "Getting mastodon posts until id")
(->>
(-> (http-client/get (-> (http-client/get
(str (@config :mastodon-host) "/api/v1/accounts/" (@config :mastodon-account-id) "/statuses") url
{:query-params {:limit limit} {:query-params {:limit limit}
:content-type :json :content-type :json
:as :json}) :as :json})
:body :body
(utils/validate-with-throw post-res-schema))] (utils/validate-with-throw post-res-schema))
(take-while #(not= (:id %) id) posts))) (take-while #(not= (:id %) id)))))
(defn extract-images [post]
(let [images (get-in post [:embed :images] [])]
(map #(vector (:fullsize %) (:alt %)) images)))
(defn run [] (defn run []
(tel/log! :info "Running mastodon fetcher") (tel/log! :info "Running mastodon fetcher")
(let [last-saved-id (pb/get-latest-post-remote-id-by-source :mastodon) (let [last-saved-id (pb/get-latest-post-remote-id-by-source :mastodon)
new-posts (reverse (get-posts-until-id last-saved-id))] new-posts (reverse (get-posts-until-id last-saved-id))]
(tel/log! {:level :info :data {:count (if (nil? new-posts) 0 (count new-posts))}} "Found new posts to save")
(->> new-posts (->> new-posts
(map #(hash-map :source :mastodon (map #(hash-map :source :mastodon
:fullPost % :fullPost %

View file

@ -18,11 +18,11 @@
(> (.toHours duration) 23)))) ; 23 to be safe, or use 24 (> (.toHours duration) 23)))) ; 23 to be safe, or use 24
(defn get-new-login-token [] (defn get-new-login-token []
(tel/log! :info "Getting new login token")
(let [user-name (@config :pocket-base-user) (let [user-name (@config :pocket-base-user)
pw (@config :pocket-base-pw) pw (@config :pocket-base-pw)
body {:identity user-name :password pw} body {:identity user-name :password pw}
url (str (@config :pocket-base-host) "/api/collections/users/auth-with-password")] url (str (@config :pocket-base-host) "/api/collections/users/auth-with-password")]
(tel/log! {:level :info :data {:url url}} "Getting new login token")
(-> (->
(http-client/post url (http-client/post url
{:form-params body {:form-params body