diff --git a/env/prod/resources/config.edn b/env/prod/resources/config.edn index 07c9b93..afa2943 100644 --- a/env/prod/resources/config.edn +++ b/env/prod/resources/config.edn @@ -4,5 +4,5 @@ :app_key "applicationkey" :app_secret "applicationsecret" :user_token "simon-brooke-ireadit" - :user_secret "somesortofnonsense" + :user_secret "Tartillyan" :bot_account "IReadIt"} diff --git a/src/clj/ireadit/bot/responder.clj b/src/clj/ireadit/bot/responder.clj index 7e59e31..ae76aa4 100644 --- a/src/clj/ireadit/bot/responder.clj +++ b/src/clj/ireadit/bot/responder.clj @@ -37,7 +37,7 @@ ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, ;;;; USA. ;;;; -;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign +;;;; Copyright (C) 2019 Simon Brooke ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/clj/ireadit/routes/home.clj b/src/clj/ireadit/routes/home.clj index fcbf44d..2dcf0bd 100644 --- a/src/clj/ireadit/routes/home.clj +++ b/src/clj/ireadit/routes/home.clj @@ -4,6 +4,29 @@ [ring.util.http-response :as response] [clojure.java.io :as io])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; ireadit.routes.home: User-oriented web interface. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2019 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (defn home-page [] (layout/render "home.html")) diff --git a/src/clj/ireadit/routes/services.clj b/src/clj/ireadit/routes/services.clj index fbf15cc..2670f40 100644 --- a/src/clj/ireadit/routes/services.clj +++ b/src/clj/ireadit/routes/services.clj @@ -6,6 +6,30 @@ [ring.util.http-response :refer :all] [schema.core :as s])) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; ireadit.routes.services: JSON API. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2019 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + (def service-routes (api {:swagger {:ui "/swagger-ui" diff --git a/src/clj/ireadit/splitter.clj b/src/clj/ireadit/splitter.clj new file mode 100644 index 0000000..13e67bc --- /dev/null +++ b/src/clj/ireadit/splitter.clj @@ -0,0 +1,72 @@ +(ns ireadit.splitter + (:require [clojure.string :as s])) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; ireadit.splitter: split OCR output into individual tweets. +;;;; +;;;; This program is free software; you can redistribute it and/or +;;;; modify it under the terms of the GNU General Public License +;;;; as published by the Free Software Foundation; either version 2 +;;;; of the License, or (at your option) any later version. +;;;; +;;;; This program is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with this program; if not, write to the Free Software +;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +;;;; USA. +;;;; +;;;; Copyright (C) 2019 Simon Brooke +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + + +(def prologue + "Prologue for the first tweet in a thread of tweets." + "I read it as: \"") + +(def continuation + "Epilogue of a single tweet for with there will be a successor." + ">>>") + +(def usable-length + "The maximum length of the payload of a single tweet" + (- 220 (+ (count prologue) (count continuation)))) + +(defn count-tweet + "Count the number of characters in a tweet constructed from this list of tokens." + [tokens] + (+ (count (rest tokens)) (reduce + (map count tokens)))) + +(defn construct-tweets + "Take this list of tokens, and return a lost of strings representing + individual tweets" + ([tokens] + (let [tweets (map + #(s/join " " (reverse %)) + (construct-tweets tokens nil))] + (cons (str prologue (first tweets)) (rest tweets)))) + ([tokens tweet] + (cond + (empty? tokens) (list (cons "\"" tweet)) + (< + (+ + (count-tweet tweet) + (count (first tokens))) + usable-length) + (construct-tweets (rest tokens) (cons (first tokens) tweet)) + true + (cons + (cons continuation tweet) + (construct-tweets tokens nil))))) + +(defn split-into-tweets + [input] + (if + (string? input) + (split-into-tweets (s/split input #"\s+")) + (construct-tweets input))) diff --git a/src/clj/ireadit/tesseractor.clj b/src/clj/ireadit/tesseractor.clj index 4e85937..f94a62c 100644 --- a/src/clj/ireadit/tesseractor.clj +++ b/src/clj/ireadit/tesseractor.clj @@ -28,7 +28,7 @@ ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, ;;;; USA. ;;;; -;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign +;;;; Copyright (C) 2019 Simon Brooke ;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/test/clj/ireadit/test/splitter.clj b/test/clj/ireadit/test/splitter.clj new file mode 100644 index 0000000..0c54b12 --- /dev/null +++ b/test/clj/ireadit/test/splitter.clj @@ -0,0 +1,33 @@ +(ns ireadit.test.splitter + (:require [clojure.string :as s] + [clojure.test :refer :all] + [ring.mock.request :refer :all] + [ireadit.splitter :refer :all] + [ireadit.middleware.formats :as formats] + [muuntaja.core :as m] + [mount.core :as mount])) + +(deftest test-splitter + (testing "Splitting a string into tweets" + (let [test-input "We believe that the Scottish Parliament should have the + right to hold another referendum if there is clear and sustained + evidence that independence has become the preferred option of a + majority of the Scottish people — or if there is a significant + and material change in the circumstances that prevailed in 2014, + such as Scotland being taken out of the EU against our will." + expected (list "I read it as: \"We believe that the Scottish Parliament should have the right to hold another referendum if there is clear and sustained evidence that independence has become the preferred option of a majority of the >>>" + "Scottish people — or if there is a significant and material change in the circumstances that prevailed in 2014, such as Scotland being taken out of the EU against our will. \"") + actual (split-into-tweets test-input)] + (is (= actual expected))) + (let [test-input "We believe that the Scottish Parliament should have the + right to hold another referendum if there is clear and sustained + evidence that independence has become the preferred option of a + majority of the Scottish people — or if there is a significant + and material change in the circumstances that prevailed in 2014, + such as Scotland being taken out of the EU against our will." + tweets (split-into-tweets test-input) + expected true + actual (s/starts-with? (first tweets) prologue)] + (is (= actual expected))) + )) +