From db46e307f89a4ac37f75a6057f0b0c153d0d8ebd Mon Sep 17 00:00:00 2001 From: Charles Fourdrignier Date: Sun, 28 Jan 2018 13:27:38 +0100 Subject: [PATCH] Init Clojure project --- .gitignore | 6 +++++- .travis.yml | 5 +---- README.md | 6 +++++- project.clj | 3 +++ src/playground.clj | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 project.clj create mode 100644 src/playground.clj diff --git a/.gitignore b/.gitignore index 7186def..b836965 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .gradle build/ +target/ # Ignore Gradle GUI config gradle-app.setting @@ -10,4 +11,7 @@ gradle-app.setting # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar -*~ \ No newline at end of file +*~ + +.lein-repl-history +.nrepl-port \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2b2dfcb..4f42080 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1 @@ -language: java - -jdk: - - oraclejdk8 \ No newline at end of file +language: clojure \ No newline at end of file diff --git a/README.md b/README.md index d7e7aab..582c0b0 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # library-monkey -Substitute for 'check-mediatheque' project + +Currently rewrite the project with Clojure. + +Previous project was for the library of the city "Lomme", this version is for the city of "Amiens". + diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..1a04c50 --- /dev/null +++ b/project.clj @@ -0,0 +1,3 @@ +(defproject library-monkey "0.1.0" + :dependencies [[org.clojure/clojure "1.9.0"] + [http-kit "2.2.0"]]) \ No newline at end of file diff --git a/src/playground.clj b/src/playground.clj new file mode 100644 index 0000000..7720609 --- /dev/null +++ b/src/playground.clj @@ -0,0 +1,33 @@ +(require '[org.httpkit.client :as http]) + +(defn find-auth [cookies] + (->> + (clojure.string/split cookies #"; (path=/,)?") + (filter #(clojure.string/includes? % "S_ARCHIMED_CRYSTAL_AUTH=EXPLOITATION")) + (first))) + + +(defn auth-cookie [name password] + (let [response + @(http/post "http://bibliotheques.amiens.fr/CDA/pages/logon.aspx?INSTANCE=EXPLOITATION" + { + :form-params { + :name name + :pwd password + } + :follow-redirects false + })] + ((comp find-auth :set-cookie :headers) response))) + +(defn get-borrowings [cookie] + (let [response + @(http/get "http://bibliotheques.amiens.fr/cda/default.aspx?INSTANCE=EXPLOITATION&PORTAL_ID=erm_portal_services.xml&PAGE=/clientBookline/recherche/dossier_lecteur.asp%3FINSTANCE%3DEXPLOITATION%26OUTPUT%3DCANVAS%26STRCODEDOCBASE%3DCAAM" + { + :headers { + "Accept" "application/json" + "Cookie" cookie + } + :follow-redirects false + })] + (println (:error response)) + (println (:status response))))