diff --git a/project.clj b/project.clj index 6dfc352..9430fcf 100644 --- a/project.clj +++ b/project.clj @@ -1,5 +1,7 @@ (defproject inmanis "0.1.0-SNAPSHOT" :description "Fix the Internet of shit" :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}) diff --git a/src/inmanis/core.clj b/src/inmanis/core.clj index 03a7781..bd32e15 100644 --- a/src/inmanis/core.clj +++ b/src/inmanis/core.clj @@ -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 "I don't do a whole lot."