hook up is tech

This commit is contained in:
Travis Shears 2025-08-14 19:17:35 +02:00
parent 0cfefc5f04
commit 672e1944b0
5 changed files with 40 additions and 1 deletions

View file

@ -3,6 +3,7 @@
[clj-http.client :as http-client]
[micro-blog.pocket-base :as pb]
[micro-blog.utils :as utils]
[micro-blog.is-tech]
[taoensso.telemere :as tel]
[micro-blog.config :refer [config]]))
@ -84,6 +85,7 @@
(hash-map :source :blue_sky
:fullPost post
:remoteId (:cid post)
:isTech (micro-blog.is-tech/is-tech? (:record post))
:authorId (get-in post [:author :handle])
:tags (extract-tags post)
:images (extract-images post)

View file

@ -4,7 +4,7 @@
{:pocket-base-pw "POCKET_BASE_PW"
:pocket-base-host "POCKET_BASE_HOST"
:blue-sky-api-key "BLUE_SKY_API_KEY"
:minstral-api-key "MISTRAL_API_KEY"
:mistral-api-key "MISTRAL_API_KEY"
:mastodon-host "MASTODON_BASE_URL"
:mastodon-account-id "MASTODON_ACCOUNT_ID"
:api-host "API_HOST"

View file

@ -1,6 +1,7 @@
(ns micro-blog.is-tech
(:require
[micro-blog.config :refer [config]]
[taoensso.telemere :as tel]
[clj-http.client :as client]))
(defn call-mistral-api [post-text]
@ -11,6 +12,7 @@
body {:inputs post-text
:stream false
:agent_id (@config :mistral-agent-id)}]
(tel/log! {:level :info :data {:url url :agent_id (:agent_id body)}} "making request to mistral agent")
(->
(client/post url {:headers headers
:form-params body

View file

@ -2,6 +2,7 @@
(:require
[clj-http.client :as http-client]
[micro-blog.config :refer [config]]
[micro-blog.is-tech]
[micro-blog.pocket-base :as pb]
[micro-blog.utils :as utils]
[taoensso.telemere :as tel]))
@ -44,6 +45,7 @@
(tel/log! {:level :info :data {:remoteId (:id raw-post)}} "Transforming mastodon post")
(hash-map
:source :mastodon
:isTech (micro-blog.is-tech/is-tech? (:content raw-post))
:fullPost raw-post
:remoteId (:id raw-post)
:authorId (get-in raw-post [:account :id])

View file

@ -43,6 +43,30 @@
(defn valid-source? [source]
(m/validate source-enum source))
(defn get-all-posts-by-source
([source] (get-all-posts-by-source source [] 1))
([source carry page]
(when (not (valid-source? source))
(throw (ex-info "Invalid source" {:source source})))
(let [url (str (@config :pocket-base-host) "/api/collections/micro_blog_posts/records")
headers {"Authorization" (get-login-token-with-cache)}
page-size 15
rows (-> (http-client/get url
{:headers headers
:query-params {:page page
"perPage" page-size
:sort "-posted"
:filter (str "source = '" (name source) "'")
"skipTotal" true}
:content-type :json
:as :json})
:body
:items)]
(if
(< (count rows) page-size)
(concat carry rows)
(get-all-posts-by-source source (concat carry rows) (inc page))))))
(defn get-latest-post-remote-id-by-source [source]
(let [res-schema
[:map
@ -154,6 +178,7 @@
(let [save-post-schema [:map
[:source source-enum]
[:fullPost :any]
[:isTech :boolean]
[:tags [:sequential :string]]
[:images [:sequential [:tuple :string :string]]]
[:remoteId :string]
@ -171,3 +196,11 @@
:images (map #(apply get-image-id %) (:images post)))
:content-type :json
:as :json}))))
(defn set-is-tech [post-id is-tech]
(tel/log! {:level :info :data {:post-id post-id}} "Setting post.is-tech to yes_ai")
(http-client/patch (str (@config :pocket-base-host) "/api/collections/micro_blog_posts/records/" post-id)
{:headers {"Authorization" (get-login-token-with-cache)}
:form-params {:isTech (if is-tech "yes_ai" "no")}
:content-type :json
:as :json}))