From 3c63d1b5e0f6cd24f36ca8172af2a07dd69c50b6 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 16 Dec 2021 19:35:14 +0100 Subject: [PATCH] Remove futures --- .gitignore | 6 +++++- Makefile | 1 - project.clj | 2 +- src/rsspaper/feeds.clj | 45 ++++++++++++++++++++++-------------------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index f00ae81..3549330 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ target/ config.yaml log/logger1.log* *.jar -resources/*.tar \ No newline at end of file +resources/*.tar +resources/themes/clojure/static.tar +resources/themes/dark/static.tar +resources/themes/light/static.tar +resources/themes/sepia/static.tar diff --git a/Makefile b/Makefile index f354cc1..0114dc7 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ build: make build.templates lein uberjar - make rm.statics echo "Finish!" build.templates: diff --git a/project.clj b/project.clj index 1b86d39..1d0dfa0 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject rsspaper "1.2.1" +(defproject rsspaper "1.2.2" :description "RSSpaper" :url "https://github.com/tanrax/RSSpaper" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" diff --git a/src/rsspaper/feeds.clj b/src/rsspaper/feeds.clj index 73331b3..194f3f6 100644 --- a/src/rsspaper/feeds.clj +++ b/src/rsspaper/feeds.clj @@ -16,13 +16,17 @@ (defn filter-edition [articles] - (let [daily (c/to-long (t/minus (t/now) (t/days 1))) + (let [daily (c/to-long (t/minus (t/now) (t/days 1))) weekly (c/to-long (t/minus (t/now) (t/weeks 1)))] (case (:edition config) - "daily" (filter (fn [article] (and (not (nil? (:published-date article))) (>= (:published-date article) daily))) articles) + "daily" (filter (fn [article] (and (not (nil? (:published-date article))) (>= (:published-date article) daily))) articles) "weekly" (filter (fn [article] (and (not (nil? (:published-date article))) (>= (:published-date article) weekly))) articles) articles))) +(defn remove-future-editions + [articles] + (filter (fn [article] (and (not (nil? (:published-date article))) (< (:published-date article) (c/to-long (t/now))))) articles)) + (defn add-datetimes-formatter [articles] (map (fn [article] @@ -35,10 +39,9 @@ ;; Add in every article, all information from feed (concat articles (map (fn [article] (assoc ;; Add feed-url - (assoc article :feed + (assoc article :feed ;; Add feed - (:feed (update-in feed [:feed] dissoc :entries))) :feed-url (:feed-url feed))) (get-in feed [:feed :entries])))) [] feeds)) - + (:feed (update-in feed [:feed] dissoc :entries))) :feed-url (:feed-url feed))) (get-in feed [:feed :entries])))) [] feeds)) (defn add-domain-to-relative-path [url-complete url-relative] @@ -49,7 +52,6 @@ url-with-domain (if is-relative (str (get url-elements 1) (get url-elements 2) url-relative) url-relative)] url-with-domain)) - (defn add-cover-article [articles] ;; Add cover to article search first image in description @@ -63,7 +65,7 @@ url-og-image (second (re-find #"].*?property=\"og:image(?::url)?\".*?content=\"(.*?)\".*?>|].*?content=\"(.*?)\".*?property=\"og:image(?::url)?\".*?>" html)) url-first-image (second (re-find #"[\s\S]+]+src=\"([^\">]+)\"|id=['\"] ?main ?['\"]>[\s\S]+]+src=\"([^\">]+)\"|class=['\"] ?main ?[\'\"]>[\s\S]+]+src=\"([^\">]+)\"" html)) images [url-og-image url-first-image] - url-valid (first (filter (fn [item] (not (nil? item))) images)) + url-valid (first (remove nil? images)) url-final-image (add-domain-to-relative-path (:feed-url article) url-valid)] (assoc article :cover url-final-image))) articles)) @@ -76,22 +78,23 @@ [] ;; Get all feeds from config -> feeds (-> - (reduce - (fn [feeds feed-url] + (reduce + (fn [feeds feed-url] ; Read feed - (let [feed (parse-url feed-url {:insecure? true :throw-exceptions false})] + (let [feed (parse-url feed-url {:insecure? true :throw-exceptions false})] ; User feedback - (prn (str "Reading RSS > " feed-url)) + (prn (str "Reading RSS > " feed-url)) ; Check is not null - (if-not (nil? feed) + (if-not (nil? feed) ; Add feed and add key feed original - (conj feeds (assoc feed :feed-url feed-url)) + (conj feeds (assoc feed :feed-url feed-url)) ; Alert fail - (prn (str "Error with '" feed-url) "'")))) - [] (:feeds config)) - zip-feeds-in-articles - datetimes-to-unixtime - filter-edition - order-published - add-cover-article - add-datetimes-formatter)) + (prn (str "Error with '" feed-url) "'")))) + [] (:feeds config)) + zip-feeds-in-articles + datetimes-to-unixtime + filter-edition + remove-future-editions + order-published + add-cover-article + add-datetimes-formatter))