get saving of blue sky posts working

TODO: blue sky tags
TODO: blue sky images
This commit is contained in:
Travis Shears 2025-07-20 13:12:12 +02:00
parent c247774256
commit d6c4254e94
3 changed files with 65 additions and 6 deletions

View file

@ -32,7 +32,15 @@
[:author [:map
[:handle :string]]]
[:embed {:optional true}
[:map [:images {:optional true} [:vector [:map
[:fullsize :string]
[:alt :string]]]]]]
[:record [:map
[:facets {:optional true} [:vector [:map
[:features [:vector [:map
[:$type :string]
[:tag {:optional true} [:maybe :string]]]]]]]]
[:createdAt :string]]]]]]]]])
(defn get-posts-until-id
@ -75,9 +83,27 @@
;; "RELATION_RECORD_ID"
;; ]
;; };
;;
(defn extract-tags [post]
(let [facets (get (post :record) :facets [])
features (flatten (map :features facets))
tag-features (filter #(= (:$type %) "app.bsky.richtext.facet#tag") features)
tags (map :tag tag-features)]
tags))
(defn extract-images [post]
(let [images (get-in post [:embed :images] [])]
(map #(hash-map :url (:fullsize %) :alt (:alt %)) images)))
(defn run []
(let [session (create-session)
last-saved-id (pb/get-latest-post-remote-id-by-source :blue_sky)
new-posts (get-posts-until-id session last-saved-id)]
{:session session :last-saved-id last-saved-id :new-posts new-posts}))
new-posts (reverse (get-posts-until-id session last-saved-id))]
(->> new-posts
(map #(hash-map :source :blue_sky
:fullPost %
:remoteId (:cid %)
:authorId (get-in % [:author :handle])
:posted (get-in % [:record :createdAt])))
(map pb/save-post))))