work branch
This commit is contained in:
parent
97a1125695
commit
05e84bab61
@ -5,7 +5,7 @@
|
|||||||
:dependencies [[org.clojure/clojure "1.10.0"]
|
:dependencies [[org.clojure/clojure "1.10.0"]
|
||||||
[compojure "1.6.1"]
|
[compojure "1.6.1"]
|
||||||
[ring/ring-defaults "0.3.2"]
|
[ring/ring-defaults "0.3.2"]
|
||||||
[http.async.client "1.3.1"]
|
[clj-http "3.10.1"]
|
||||||
[hickory "0.7.1"]]
|
[hickory "0.7.1"]]
|
||||||
:plugins [[lein-ring "0.12.5"]]
|
:plugins [[lein-ring "0.12.5"]]
|
||||||
:ring {:handler clojsa.handler/app}
|
:ring {:handler clojsa.handler/app}
|
||||||
|
@ -3,3 +3,9 @@ document.body.addEventListener('configRequest.htmx', (e) => {
|
|||||||
e.detail.parameters['__anti-forgery-token'] = __csrfToken;
|
e.detail.parameters['__anti-forgery-token'] = __csrfToken;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll('.bbc-spoiler').forEach(elem => {
|
||||||
|
elem.addEventListener('click', e => {
|
||||||
|
e.target.classList.toggle('active');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
(ns clojsa.handler
|
(ns clojsa.handler
|
||||||
(:require [clojsa.views :as views]
|
(:require [clojsa.saparser :as parser]
|
||||||
[clojsa.saclient :as client]
|
[clojsa.saclient :as client]
|
||||||
[clojsa.saparser :as parser]
|
[clojsa.views :as views]
|
||||||
[compojure.core :refer :all]
|
[compojure.core :refer :all]
|
||||||
[compojure.route :as route]
|
[compojure.route :as route]
|
||||||
[compojure.coercions :refer [as-int]]
|
[compojure.coercions :refer [as-int]]
|
||||||
@ -9,23 +9,31 @@
|
|||||||
[ring.middleware.session :refer [wrap-session]]
|
[ring.middleware.session :refer [wrap-session]]
|
||||||
[ring.middleware.session.cookie :refer (cookie-store)]))
|
[ring.middleware.session.cookie :refer (cookie-store)]))
|
||||||
|
|
||||||
|
(def session-cookie-store (cookie-store {:key "b91c62d40a1fd146"}))
|
||||||
(defn get-thread [session id page]
|
|
||||||
(let [turl (client/thread-url id page)
|
|
||||||
tresp (client/thread-response session turl)]
|
|
||||||
(parser/thread-map id page tresp)))
|
|
||||||
|
|
||||||
(defroutes app-routes
|
(defroutes app-routes
|
||||||
(GET "/" request (views/index-page request))
|
(GET "/" request (views/index-page request))
|
||||||
|
(GET "/login" {session :session}
|
||||||
|
(let [login-cookies (client/do-login)]
|
||||||
|
{:status 302
|
||||||
|
:headers {"Location" "/thread/3814875?page=29"}
|
||||||
|
:session (assoc session :cookies login-cookies)}))
|
||||||
|
|
||||||
(GET "/thread/:id" [id :<< as-int
|
(GET "/thread/:id" [id :<< as-int
|
||||||
page :<< as-int
|
page :<< as-int
|
||||||
:as {session :session}]
|
:as {session :session}]
|
||||||
(let [thread (get-thread session id page)]
|
(let [thread (assoc (parser/get-thread session id page) :page page)
|
||||||
(views/thread-page thread)))
|
count (:count session 0)
|
||||||
|
session (assoc session :count (inc count))]
|
||||||
|
{:body (views/thread-page thread session)
|
||||||
|
:headers {"Content-Type" "text/html; charset=utf-8"}
|
||||||
|
:session session}))
|
||||||
|
|
||||||
(route/not-found "Not Found"))
|
(route/not-found "Not Found"))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(-> app-routes
|
(-> app-routes
|
||||||
(wrap-defaults site-defaults)
|
(wrap-defaults site-defaults)
|
||||||
(wrap-session {:cookie-attrs {:max-age 3600}
|
(wrap-session {:cookie-name "clojsa-session"
|
||||||
:store (cookie-store {:key "12345678abcdefgh"})})))
|
:cookie-attrs {:max-age (* 7 24 3600)}
|
||||||
|
:store session-cookie-store})))
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
(ns clojsa.saclient
|
(ns clojsa.saclient
|
||||||
(:require [clojure.string :as string]
|
(:require [clj-http.client :as client]))
|
||||||
[http.async.client :as http]))
|
|
||||||
|
|
||||||
|
|
||||||
(def url "https://forums.somethingawful.com/")
|
(def url "https://forums.somethingawful.com/")
|
||||||
|
|
||||||
|
(defn cookie-store [cookies]
|
||||||
|
(let [cs (clj-http.cookies/cookie-store)
|
||||||
|
v (vec cookies)]
|
||||||
|
(for [c v]
|
||||||
|
(println c))
|
||||||
|
cs))
|
||||||
|
|
||||||
(defn thread-url
|
(defn thread-url
|
||||||
([id]
|
([id]
|
||||||
(thread-url id 1))
|
(thread-url id 1))
|
||||||
@ -14,12 +19,20 @@
|
|||||||
:pagenumber page}]
|
:pagenumber page}]
|
||||||
{:href base-url :params query})))
|
{:href base-url :params query})))
|
||||||
|
|
||||||
|
(defn do-login []
|
||||||
|
(let [login-url (str url "account.php")
|
||||||
|
cs (clj-http.cookies/cookie-store)]
|
||||||
|
(client/post login-url {:form-params {:action "login"
|
||||||
|
:username "xf86enodev"
|
||||||
|
:password "triebhaftigke1t"}
|
||||||
|
:cookie-store cs})
|
||||||
|
(clj-http.cookies/get-cookies cs)))
|
||||||
|
|
||||||
(defn thread-response [session url]
|
(defn thread-response [session url]
|
||||||
(with-open [client (http/create-client)]
|
(let [cs (cookie-store (:cookies session))
|
||||||
(let [{:keys [href params]} url
|
resp (client/get (:href url) {:query-params (:params url)
|
||||||
resp (http/GET client href :query params)
|
:cookie-store cs
|
||||||
status (http/status resp)
|
:debug false})]
|
||||||
headers (http/headers resp)]
|
(:body resp)))
|
||||||
(-> resp
|
|
||||||
http/await
|
;; (def witcher-thread (thread-response (thread-url 3720352 3)))
|
||||||
http/string))))
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
(let [pb (-> pb :content)]
|
(let [pb (-> pb :content)]
|
||||||
(hickory-to-hiccup (hickory-div "postbody" pb))))
|
(hickory-to-hiccup (hickory-div "postbody" pb))))
|
||||||
|
|
||||||
(defn thread-map [id page doc]
|
(defn thread-map [id doc]
|
||||||
(let [htree (hickory-doc doc)
|
(let [htree (hickory-doc doc)
|
||||||
title (parse-title htree)
|
title (parse-title htree)
|
||||||
page-count (parse-pagecount htree)
|
page-count (parse-pagecount htree)
|
||||||
@ -54,10 +54,12 @@
|
|||||||
postbody (select-td :postbody thread-tree)]
|
postbody (select-td :postbody thread-tree)]
|
||||||
{:title title
|
{:title title
|
||||||
:id id
|
:id id
|
||||||
:page page
|
|
||||||
:page-count page-count
|
:page-count page-count
|
||||||
:content
|
:content
|
||||||
(for [[ui pd pb] (partition 3 (interleave userinfo postdate postbody))
|
(for [[ui pd pb] (partition 3 (interleave userinfo postdate postbody))
|
||||||
:when (not= "Adbot" (-> (s/select (s/child (s/class :author)) ui)
|
:when (not= "Adbot" (-> (s/select (s/child (s/class :author)) ui)
|
||||||
first :content first))]
|
first :content first))]
|
||||||
{:ui (parse-ui ui) :pd (parse-pd pd) :pb (parse-pb pb)})}))
|
{:ui (parse-ui ui) :pd (parse-pd pd) :pb (parse-pb pb)})}))
|
||||||
|
|
||||||
|
(defn get-thread [session id page]
|
||||||
|
(thread-map id (thread-response session (thread-url id page))))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
(ns clojsa.views
|
(ns clojsa.views
|
||||||
(:use [hiccup core page])
|
(:use [hiccup core page])
|
||||||
(:require [clojure.string :as string]
|
(:require
|
||||||
[clojure.pprint]
|
[clojure.string :as string]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[cheshire.core :as json]))
|
[cheshire.core :as json]))
|
||||||
|
|
||||||
@ -30,13 +30,14 @@
|
|||||||
(include-js "/js/main.js")]))
|
(include-js "/js/main.js")]))
|
||||||
|
|
||||||
(defn index-page [req]
|
(defn index-page [req]
|
||||||
(main-template {}
|
(main-template
|
||||||
[:div.container
|
{}
|
||||||
[:pre
|
[:div.container
|
||||||
(clojure.pprint/pprint req)]]))
|
[:pre.output
|
||||||
|
[:code (with-out-str (clojure.pprint/pprint req))]]]))
|
||||||
|
|
||||||
(defn paginate [id cur last]
|
(defn paginate [id cur last]
|
||||||
[:nav.container.pagination {:hx-boot "false"}
|
[:nav.container.box.pagination {:hx-boot "false"}
|
||||||
[:a.pagination-previous
|
[:a.pagination-previous
|
||||||
{:href (format "/thread/%d?page=%d" id (dec cur))} "<"]
|
{:href (format "/thread/%d?page=%d" id (dec cur))} "<"]
|
||||||
[:a.pagination-next
|
[:a.pagination-next
|
||||||
@ -58,18 +59,26 @@
|
|||||||
[:a.pagination-link
|
[:a.pagination-link
|
||||||
{:href (format "/thread/%d?page=%d" id last)} (str last)]]]])
|
{:href (format "/thread/%d?page=%d" id last)} (str last)]]]])
|
||||||
|
|
||||||
(defn thread-page [thread]
|
(defn thread-page [thread session]
|
||||||
(let [{:keys [id title page page-count content]} thread]
|
(let [{:keys [id title page page-count content]} thread]
|
||||||
(main-template
|
(main-template
|
||||||
{:title title}
|
{:title title}
|
||||||
[:div.container
|
[:div.container
|
||||||
|
[:pre.output
|
||||||
|
[:code (with-out-str (clojure.pprint/pprint session))]]
|
||||||
[:h1.is-size-3.mb-4 title]]
|
[:h1.is-size-3.mb-4 title]]
|
||||||
[:section.thread
|
[:section.thread
|
||||||
(for [post content]
|
(for [post content]
|
||||||
[:article.container.box.columns
|
[:article.container.box
|
||||||
[:aside.userinfo.column
|
[:div.tile.is-ancestor
|
||||||
(:ui post)]
|
[:aside.userinfo.tile.is-3.is-parent
|
||||||
[:main.postbody.content.column.is-four-fifths
|
(:ui post)]
|
||||||
(:pb post)]])]
|
[:main.postbody.content.tile.is-9.is-parent.is-vertical
|
||||||
|
[:div.tile.is-child
|
||||||
|
(:pb post)]
|
||||||
|
[:div.level.tile.is-child.is-12
|
||||||
|
[:div.level-right
|
||||||
|
[:span.postdate.level-item
|
||||||
|
(:pd post)]]]]]])]
|
||||||
[:section
|
[:section
|
||||||
(paginate id page page-count)])))
|
(paginate id page page-count)])))
|
||||||
|
Loading…
Reference in New Issue
Block a user