From 672e1944b0cee9d189fa1814ce7f538f7629e3ad Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Thu, 14 Aug 2025 19:17:35 +0200 Subject: [PATCH] hook up is tech --- src/micro_blog/blue_sky.clj | 2 ++ src/micro_blog/config.clj | 2 +- src/micro_blog/is_tech.clj | 2 ++ src/micro_blog/mastodon.clj | 2 ++ src/micro_blog/pocket_base.clj | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/micro_blog/blue_sky.clj b/src/micro_blog/blue_sky.clj index a7c1551..1c9579c 100644 --- a/src/micro_blog/blue_sky.clj +++ b/src/micro_blog/blue_sky.clj @@ -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) diff --git a/src/micro_blog/config.clj b/src/micro_blog/config.clj index 51528e3..c12eaef 100644 --- a/src/micro_blog/config.clj +++ b/src/micro_blog/config.clj @@ -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" diff --git a/src/micro_blog/is_tech.clj b/src/micro_blog/is_tech.clj index 6b4ee42..03cd950 100644 --- a/src/micro_blog/is_tech.clj +++ b/src/micro_blog/is_tech.clj @@ -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 diff --git a/src/micro_blog/mastodon.clj b/src/micro_blog/mastodon.clj index 1cc82aa..8b7f027 100644 --- a/src/micro_blog/mastodon.clj +++ b/src/micro_blog/mastodon.clj @@ -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]) diff --git a/src/micro_blog/pocket_base.clj b/src/micro_blog/pocket_base.clj index 35de871..05056a0 100644 --- a/src/micro_blog/pocket_base.clj +++ b/src/micro_blog/pocket_base.clj @@ -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}))