fix transform dep

This commit is contained in:
jem 2020-05-21 12:42:27 +02:00
parent 52ce74be18
commit 9cfb0fb992
2 changed files with 20 additions and 28 deletions

View file

@ -32,21 +32,16 @@
(def config (infra/load-config)) (def config (infra/load-config))
(defn in [needle haystack]
(some (partial = needle) haystack))
(defn parse-tweet [{created-at :created_at (defn parse-tweet [{created-at :created_at
text :full_text text :full_text
{:keys [media]} :extended_entities {:keys [media]} :extended_entities
{:keys [screen_name]} :user :as tweet}] {:keys [screen_name]} :user :as tweet}]
{:created-at (js/Date. created-at) {:created-at (js/Date. created-at)
:text (transform/trim-text :text (transform/trim-text
(mastodon-config config)
(str (twitter/chop-tail-media-url text media) (str (twitter/chop-tail-media-url text media)
(if (masto/append-screen-name? (mastodon-config config)) (if (masto/append-screen-name? (mastodon-config config))
(str "\n - " screen_name) ""))) (str "\n - " screen_name) ""))
(masto/max-post-length (mastodon-config config)))
:media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)}) :media-links (keep #(when (= (:type %) "photo") (:media_url_https %)) media)})
(defmulti parse-tumblr-post :type) (defmulti parse-tumblr-post :type)
@ -54,8 +49,8 @@
(defmethod parse-tumblr-post "text" [{:keys [body date short_url]}] (defmethod parse-tumblr-post "text" [{:keys [body date short_url]}]
{:created-at (js/Date. date) {:created-at (js/Date. date)
:text (str (transform/trim-text :text (str (transform/trim-text
(mastodon-config config) body
body) (masto/max-post-length (mastodon-config config)))
"\n\n" short_url)}) "\n\n" short_url)})
(defmethod parse-tumblr-post "photo" [{:keys [caption date photos short_url] :as post}] (defmethod parse-tumblr-post "photo" [{:keys [caption date photos short_url] :as post}]
@ -93,8 +88,8 @@
(for [{:keys [title isoDate pubDate content link]} (-> % infra/js->edn :items)] (for [{:keys [title isoDate pubDate content link]} (-> % infra/js->edn :items)]
{:created-at (js/Date. (or isoDate pubDate)) {:created-at (js/Date. (or isoDate pubDate))
:text (str (transform/trim-text :text (str (transform/trim-text
(mastodon-config config) title
title) (masto/max-post-length (mastodon-config config)))
"\n\n" (twitter/strip-utm link))}))))) "\n\n" (twitter/strip-utm link))})))))
(defn tumblr-client [access-keys account] (defn tumblr-client [access-keys account]

View file

@ -3,24 +3,21 @@
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[clojure.spec.test.alpha :as st] [clojure.spec.test.alpha :as st]
[orchestra.core :refer-macros [defn-spec]] [orchestra.core :refer-macros [defn-spec]]
[clojure.string :as string] [clojure.string :as string]))
;; TODO: not allowed dep - move needed config parts to this ns
[mastodon-bot.mastodon-api :as masto]))
(defn trim-text [masto-config text] (defn trim-text [text max-post-length]
(let [max-post-length (masto/max-post-length masto-config)] (cond
(cond
(nil? max-post-length) (nil? max-post-length)
text text
(> (count text) max-post-length) (> (count text) max-post-length)
(reduce (reduce
(fn [text word] (fn [text word]
(if (> (+ (count text) (count word)) (- max-post-length 3)) (if (> (+ (count text) (count word)) (- max-post-length 3))
(reduced (str text "...")) (reduced (str text "..."))
(str text " " word))) (str text " " word)))
"" ""
(string/split text #" ")) (string/split text #" "))
:else text))) :else text))