Add config
This commit is contained in:
parent
334ba97af9
commit
75d064d2a6
37
README.md
37
README.md
@ -1,44 +1,11 @@
|
||||
# isahn
|
||||
|
||||
FIXME: description
|
||||
|
||||
## Installation
|
||||
|
||||
Download from http://example.com/FIXME.
|
||||
|
||||
cp config-example.edn config.edn
|
||||
|
||||
## Usage
|
||||
|
||||
FIXME: explanation
|
||||
|
||||
$ java -jar isahn-0.1.0-standalone.jar [args]
|
||||
|
||||
## Options
|
||||
|
||||
FIXME: listing of options this app accepts.
|
||||
|
||||
## Examples
|
||||
|
||||
...
|
||||
|
||||
### Bugs
|
||||
|
||||
...
|
||||
|
||||
### Any Other Sections
|
||||
### That You Think
|
||||
### Might be Useful
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2019 FIXME
|
||||
|
||||
This program and the accompanying materials are made available under the
|
||||
terms of the Eclipse Public License 2.0 which is available at
|
||||
http://www.eclipse.org/legal/epl-2.0.
|
||||
|
||||
This Source Code may also be made available under the following Secondary
|
||||
Licenses when the conditions for such availability set forth in the Eclipse
|
||||
Public License, v. 2.0 are satisfied: GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or (at your
|
||||
option) any later version, with the GNU Classpath Exception which is available
|
||||
at https://www.gnu.org/software/classpath/license.html.
|
||||
|
@ -6,6 +6,8 @@
|
||||
:dependencies [
|
||||
; Clojure
|
||||
[org.clojure/clojure "1.10.0"]
|
||||
; Get config from .env
|
||||
[yogthos/config "1.1.4"]
|
||||
; Client HTTP
|
||||
[clj-http "3.10.0"]
|
||||
; Parse JSON
|
||||
|
@ -1,40 +1,69 @@
|
||||
(ns isahn.core
|
||||
(:require
|
||||
[config.core :refer [env]]
|
||||
[clojure.java.io :as io]
|
||||
[clj-http.client :as client]
|
||||
[cheshire.core :refer :all]
|
||||
)
|
||||
(:gen-class))
|
||||
|
||||
|
||||
" VARIABLES "
|
||||
|
||||
" URL send for Telegram "
|
||||
(def url_telegram_send (str "https://api.telegram.org/" (:bot_token env) "/sendMessage"))
|
||||
" URLs from API Hacker News "
|
||||
(def all_stories "https://hacker-news.firebaseio.com/v0/topstories.json")
|
||||
(def url_all_stories "https://hacker-news.firebaseio.com/v0/topstories.json")
|
||||
" Min score "
|
||||
(def min_score (:min_score env))
|
||||
" Now unixtime "
|
||||
(def now (quot (System/currentTimeMillis) 1000))
|
||||
" 24h in unixtime "
|
||||
(def unixtime24h 86400)
|
||||
" Now - 24h "
|
||||
(def min_time (- now unixtime24h))
|
||||
" Path file save history "
|
||||
(def path_history "isahn_history.json")
|
||||
|
||||
" FUNCTIONS "
|
||||
|
||||
(defn one_story
|
||||
" Get url from item "
|
||||
[id]
|
||||
(str "https://hacker-news.firebaseio.com/v0/item/" id ".json"))
|
||||
|
||||
" Min score "
|
||||
(def min_score 600)
|
||||
(defn get_all_stories
|
||||
" Get all stories "
|
||||
[url_all_stories]
|
||||
" Get all ids stories"
|
||||
(def ids_stories (parse-string (:body (client/get url_all_stories {:accept :json}))))
|
||||
" Get all API urls stories "
|
||||
(def urls_stories (map #(one_story %) ids_stories))
|
||||
" Get all data stories "
|
||||
(map #(parse-string (:body (client/get % {:accept :json}))) urls_stories))
|
||||
|
||||
(defn filter_stories
|
||||
[stories]
|
||||
" Filter created less 24h "
|
||||
(def stories_24h (filter #(> (get-in % ["time"]) min_time) stories))
|
||||
|
||||
" Filter with score min_score "
|
||||
(filter #(> (get-in % ["score"]) min_score) stories_24h))
|
||||
|
||||
(def now (quot (System/currentTimeMillis) 1000))
|
||||
(def unixtime24h 86400)
|
||||
|
||||
(defn -main
|
||||
"Main execution"
|
||||
[& args]
|
||||
" Get all ids stories"
|
||||
(def ids_stories (parse-string (:body (client/get all_stories {:accept :json}))))
|
||||
|
||||
" Get all API urls stories "
|
||||
(def urls_stories (map #(one_story %) ids_stories))
|
||||
|
||||
" Get all data stories "
|
||||
(def stories (map #(parse-string (:body (client/get % {:accept :json}))) urls_stories))
|
||||
|
||||
" Filter created less 24h "
|
||||
(def stories_24h (filter #(> (get-in % ["time"]) (- now unixtime24h)) stories))
|
||||
|
||||
" Filter with score min_score "
|
||||
(def stories_top (filter #(> (get-in % ["score"]) min_score) stories_24h))
|
||||
|
||||
(prn stories_top)
|
||||
[]
|
||||
;; (def stories_top (filter_stories (get_all_stories url_all_stories)))
|
||||
(def history-file (parse-string (io/file path_history)))
|
||||
(prn (slurp data-file))
|
||||
;https://stackoverflow.com/questions/7756909/in-clojure-1-3-how-to-read-and-write-a-file
|
||||
;; (doall (iterate #((client/post url_telegram_send {:basic-auth ["user" "pass"]
|
||||
;; :body (generate-string {
|
||||
;; :chat_id (:chat env)
|
||||
;; :text (str (get-in % ["title"]) ": " (get-in % ["url"]))
|
||||
;; :disable_notification true
|
||||
;; })
|
||||
;; :content-type :json
|
||||
;; :accept :json})) stories_top))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user