Add hn algolia search
This commit is contained in:
parent
184cd86264
commit
ec46de932d
2 changed files with 38 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
(defproject inmanis "0.1.0-SNAPSHOT"
|
(defproject inmanis "0.1.0-SNAPSHOT"
|
||||||
:description "Fix the Internet of shit"
|
:description "Fix the Internet of shit"
|
||||||
:url "https://gitea.esy.fun/yogsototh/inmanis-clj"
|
:url "https://gitea.esy.fun/yogsototh/inmanis-clj"
|
||||||
:dependencies [[org.clojure/clojure "1.10.1"]]
|
:dependencies [[org.clojure/clojure "1.10.1"]
|
||||||
|
[remus "0.2.2"]
|
||||||
|
[metosin/malli "0.6.1"]]
|
||||||
:repl-options {:init-ns inmanis.core})
|
:repl-options {:init-ns inmanis.core})
|
||||||
|
|
|
@ -1,4 +1,38 @@
|
||||||
(ns inmanis.core)
|
(ns inmanis.core
|
||||||
|
(:require [remus :refer [parse-url]]
|
||||||
|
[clojure.string :as string]
|
||||||
|
[malli.core :as m]
|
||||||
|
))
|
||||||
|
|
||||||
|
(defn get-item-url [id] (format "http://hn.algolia.com/api/v1/items/%s" id))
|
||||||
|
(defn get-user-url [username] (format "http://hn.algolia.com/api/v1/users/%s" username))
|
||||||
|
|
||||||
|
(def HNQuery
|
||||||
|
[:map
|
||||||
|
[:query string?]
|
||||||
|
[:tags (fn [t]
|
||||||
|
(or (#{:story :comment :poll :pollopt :show_hn :ask_hn :front_page} t)
|
||||||
|
(string/starts-with? t "author_:")
|
||||||
|
(string/starts-with? t "story_:")))]
|
||||||
|
[:numericFilters
|
||||||
|
[:vector [:re #"(created_at_i|points|comments)(<|<=|=|>|>=)\d+"]]]
|
||||||
|
[:page int?]])
|
||||||
|
|
||||||
|
(def HTTPQuery
|
||||||
|
[:map
|
||||||
|
[:url string?]
|
||||||
|
[:query-params {:optional true} any?]
|
||||||
|
[:form-params {:optional true} any?]])
|
||||||
|
|
||||||
|
(defn search [hn-query]
|
||||||
|
{:url "http://hn.algolia.com/api/v1/search"
|
||||||
|
:query-params hn-query})
|
||||||
|
|
||||||
|
(m/=> search [:=> [:cat HNQuery] HTTPQuery])
|
||||||
|
|
||||||
|
(defn retrieve-hn-top []
|
||||||
|
(let [resp (parse-url "https://hnrss.org/newest?points=1200")]
|
||||||
|
(count (get-in resp [:feed :entries]))))
|
||||||
|
|
||||||
(defn foo
|
(defn foo
|
||||||
"I don't do a whole lot."
|
"I don't do a whole lot."
|
||||||
|
|
Loading…
Reference in a new issue