Update comments
This commit is contained in:
parent
c7383a6a5a
commit
b774884cce
@ -8,19 +8,19 @@
|
|||||||
|
|
||||||
;; VARIABLES
|
;; VARIABLES
|
||||||
|
|
||||||
" URL send for Telegram "
|
;; URL send for Telegram
|
||||||
(def url_telegram_send (str "https://api.telegram.org/" (:bot_token env) "/sendMessage"))
|
(def url_telegram_send (str "https://api.telegram.org/" (:bot_token env) "/sendMessage"))
|
||||||
" URLs from API Hacker News "
|
;; URLs from API Hacker News
|
||||||
(def url_all_stories "https://hacker-news.firebaseio.com/v0/topstories.json")
|
(def url_all_stories "https://hacker-news.firebaseio.com/v0/topstories.json")
|
||||||
" Min score "
|
;; Min score
|
||||||
(def min_score (:min_score env))
|
(def min_score (:min_score env))
|
||||||
" Now unixtime "
|
;; Now unixtime
|
||||||
(def now (quot (System/currentTimeMillis) 1000))
|
(def now (quot (System/currentTimeMillis) 1000))
|
||||||
" 24h in unixtime "
|
;; 24h in unixtime
|
||||||
(def unixtime24h 86400)
|
(def unixtime24h 86400)
|
||||||
" Now - 24h "
|
;; Now - 24h
|
||||||
(def min_time (- now unixtime24h))
|
(def min_time (- now unixtime24h))
|
||||||
" Path file save history "
|
;; Path file save history
|
||||||
(def path_history "isahn_history.json")
|
(def path_history "isahn_history.json")
|
||||||
(def history (if (.exists (io/file path_history)) (json/parse-string (slurp (io/file path_history)) true) (str "")))
|
(def history (if (.exists (io/file path_history)) (json/parse-string (slurp (io/file path_history)) true) (str "")))
|
||||||
(def history_ids (map :id history))
|
(def history_ids (map :id history))
|
||||||
@ -35,12 +35,12 @@
|
|||||||
(defn get_all_stories
|
(defn get_all_stories
|
||||||
" Get all stories "
|
" Get all stories "
|
||||||
[url_all_stories]
|
[url_all_stories]
|
||||||
" Get all ids stories "
|
;; Get all ids stories
|
||||||
(let [ids_stories (json/parse-string (:body (client/get url_all_stories {:accept :json})))]
|
(let [ids_stories (json/parse-string (:body (client/get url_all_stories {:accept :json})))
|
||||||
" Get all API urls stories "
|
urls_stories (map one_story ids_stories)]
|
||||||
(let [urls_stories (map one_story ids_stories)]
|
;; Get all API urls stories
|
||||||
" Get all data stories "
|
;; Get all data stories
|
||||||
(map #(json/parse-string (:body (client/get % {:accept :json}))) urls_stories))))
|
(map #(json/parse-string (:body (client/get % {:accept :json}))) urls_stories)))
|
||||||
|
|
||||||
(defn lazy-contains? [col key]
|
(defn lazy-contains? [col key]
|
||||||
(some #{key} col))
|
(some #{key} col))
|
||||||
@ -61,14 +61,13 @@
|
|||||||
(defn filter_stories
|
(defn filter_stories
|
||||||
"Filter stories by last 24h, remove histories and lower score"
|
"Filter stories by last 24h, remove histories and lower score"
|
||||||
[stories]
|
[stories]
|
||||||
" Filter created less 24h "
|
;; Filter created less 24h
|
||||||
(let [stories_24h (filter #(> (get-in % ["time"]) min_time) stories)]
|
(let [stories_24h (filter #(> (get-in % ["time"]) min_time) stories)
|
||||||
|
;; Filter history
|
||||||
|
stories_without_histories (filter #(not (lazy-contains? history_ids (get-in % ["id"]))) stories_24h)]
|
||||||
|
|
||||||
" Filter history "
|
;; Filter with score min_score
|
||||||
(let [stories_without_histories (filter #(not (lazy-contains? history_ids (get-in % ["id"]))) stories_24h)]
|
(filter #(> (get-in % ["score"]) min_score) stories_without_histories)))
|
||||||
|
|
||||||
" Filter with score min_score "
|
|
||||||
(filter #(> (get-in % ["score"]) min_score) stories_without_histories))))
|
|
||||||
|
|
||||||
(defn send_stories_telegram
|
(defn send_stories_telegram
|
||||||
"Send stories by Telegram Channel"
|
"Send stories by Telegram Channel"
|
||||||
@ -89,7 +88,7 @@
|
|||||||
(defn -main
|
(defn -main
|
||||||
"Main execution"
|
"Main execution"
|
||||||
[]
|
[]
|
||||||
" Run first time "
|
;; Run first time
|
||||||
(check_stories)
|
(check_stories)
|
||||||
" Run every :run_every_miliseconds "
|
;; Run every :run_every_miliseconds
|
||||||
(set-interval check_stories (:run_every_miliseconds env)))
|
(set-interval check_stories (:run_every_miliseconds env)))
|
||||||
|
Loading…
Reference in New Issue
Block a user