hook up is tech
This commit is contained in:
parent
0cfefc5f04
commit
672e1944b0
5 changed files with 40 additions and 1 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
[clj-http.client :as http-client]
|
[clj-http.client :as http-client]
|
||||||
[micro-blog.pocket-base :as pb]
|
[micro-blog.pocket-base :as pb]
|
||||||
[micro-blog.utils :as utils]
|
[micro-blog.utils :as utils]
|
||||||
|
[micro-blog.is-tech]
|
||||||
[taoensso.telemere :as tel]
|
[taoensso.telemere :as tel]
|
||||||
[micro-blog.config :refer [config]]))
|
[micro-blog.config :refer [config]]))
|
||||||
|
|
||||||
|
|
@ -84,6 +85,7 @@
|
||||||
(hash-map :source :blue_sky
|
(hash-map :source :blue_sky
|
||||||
:fullPost post
|
:fullPost post
|
||||||
:remoteId (:cid post)
|
:remoteId (:cid post)
|
||||||
|
:isTech (micro-blog.is-tech/is-tech? (:record post))
|
||||||
:authorId (get-in post [:author :handle])
|
:authorId (get-in post [:author :handle])
|
||||||
:tags (extract-tags post)
|
:tags (extract-tags post)
|
||||||
:images (extract-images post)
|
:images (extract-images post)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
{:pocket-base-pw "POCKET_BASE_PW"
|
{:pocket-base-pw "POCKET_BASE_PW"
|
||||||
:pocket-base-host "POCKET_BASE_HOST"
|
:pocket-base-host "POCKET_BASE_HOST"
|
||||||
:blue-sky-api-key "BLUE_SKY_API_KEY"
|
: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-host "MASTODON_BASE_URL"
|
||||||
:mastodon-account-id "MASTODON_ACCOUNT_ID"
|
:mastodon-account-id "MASTODON_ACCOUNT_ID"
|
||||||
:api-host "API_HOST"
|
:api-host "API_HOST"
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns micro-blog.is-tech
|
(ns micro-blog.is-tech
|
||||||
(:require
|
(:require
|
||||||
[micro-blog.config :refer [config]]
|
[micro-blog.config :refer [config]]
|
||||||
|
[taoensso.telemere :as tel]
|
||||||
[clj-http.client :as client]))
|
[clj-http.client :as client]))
|
||||||
|
|
||||||
(defn call-mistral-api [post-text]
|
(defn call-mistral-api [post-text]
|
||||||
|
|
@ -11,6 +12,7 @@
|
||||||
body {:inputs post-text
|
body {:inputs post-text
|
||||||
:stream false
|
:stream false
|
||||||
:agent_id (@config :mistral-agent-id)}]
|
: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
|
(client/post url {:headers headers
|
||||||
:form-params body
|
:form-params body
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
(:require
|
(:require
|
||||||
[clj-http.client :as http-client]
|
[clj-http.client :as http-client]
|
||||||
[micro-blog.config :refer [config]]
|
[micro-blog.config :refer [config]]
|
||||||
|
[micro-blog.is-tech]
|
||||||
[micro-blog.pocket-base :as pb]
|
[micro-blog.pocket-base :as pb]
|
||||||
[micro-blog.utils :as utils]
|
[micro-blog.utils :as utils]
|
||||||
[taoensso.telemere :as tel]))
|
[taoensso.telemere :as tel]))
|
||||||
|
|
@ -44,6 +45,7 @@
|
||||||
(tel/log! {:level :info :data {:remoteId (:id raw-post)}} "Transforming mastodon post")
|
(tel/log! {:level :info :data {:remoteId (:id raw-post)}} "Transforming mastodon post")
|
||||||
(hash-map
|
(hash-map
|
||||||
:source :mastodon
|
:source :mastodon
|
||||||
|
:isTech (micro-blog.is-tech/is-tech? (:content raw-post))
|
||||||
:fullPost raw-post
|
:fullPost raw-post
|
||||||
:remoteId (:id raw-post)
|
:remoteId (:id raw-post)
|
||||||
:authorId (get-in raw-post [:account :id])
|
:authorId (get-in raw-post [:account :id])
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,30 @@
|
||||||
(defn valid-source? [source]
|
(defn valid-source? [source]
|
||||||
(m/validate source-enum 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]
|
(defn get-latest-post-remote-id-by-source [source]
|
||||||
(let [res-schema
|
(let [res-schema
|
||||||
[:map
|
[:map
|
||||||
|
|
@ -154,6 +178,7 @@
|
||||||
(let [save-post-schema [:map
|
(let [save-post-schema [:map
|
||||||
[:source source-enum]
|
[:source source-enum]
|
||||||
[:fullPost :any]
|
[:fullPost :any]
|
||||||
|
[:isTech :boolean]
|
||||||
[:tags [:sequential :string]]
|
[:tags [:sequential :string]]
|
||||||
[:images [:sequential [:tuple :string :string]]]
|
[:images [:sequential [:tuple :string :string]]]
|
||||||
[:remoteId :string]
|
[:remoteId :string]
|
||||||
|
|
@ -171,3 +196,11 @@
|
||||||
:images (map #(apply get-image-id %) (:images post)))
|
:images (map #(apply get-image-id %) (:images post)))
|
||||||
:content-type :json
|
:content-type :json
|
||||||
:as :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}))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue