code-reviews

roelofw 2016-12-08T16:00:16.000044Z

here a url where you can see the site in action : https://lit-lowlands-46138.herokuapp.com/

gdeer81 2016-12-08T18:03:16.000046Z

Sorry @roelofw I didn't realize I wasn't in this channel

roelofw 2016-12-08T18:03:51.000047Z

NP

gdeer81 2016-12-08T18:08:02.000048Z

I like to pull down repos and run them locally but it looks like I can't since I need an api key. First thing I suggest is to update the readme with the purpose, if you can run it locally, design decisions you made, etc.

roelofw 2016-12-08T18:08:40.000049Z

I can give you the same api key as I use in a pm

snoe 2016-12-08T18:09:54.000050Z

@roelofw you can pass a :query-params map instead of building the query-string manually e..g here https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj#L39

roelofw 2016-12-08T18:10:36.000053Z

@snoe : oke , can I then have the same url as before

roelofw 2016-12-08T18:11:10.000054Z

you mean the key and format part ?

snoe 2016-12-08T18:11:13.000055Z

yeah

roelofw 2016-12-08T18:11:50.000056Z

oke, I will hit the manual of clj-http how to do that

snoe 2016-12-08T18:12:08.000057Z

you can drop everything after the '?' and put it in a map like {:format "json" :key apikey}

roelofw 2016-12-08T18:12:51.000058Z

oke, but the key must be a secret so I have to pull it out with environ

roelofw 2016-12-08T18:14:34.000059Z

so it will be (client/get {:as :json :format "json" :key (env :key}) as I understand your right ?

roelofw 2016-12-08T18:15:40.000061Z

and the sentece above it , will be (str <https://www.rijksmuseum.nl/api/nl/collection/>" id "/tiles?")

snoe 2016-12-08T18:16:31.000062Z

not quite (client/get (str "<https://www.rijksmuseum.nl/api/nl/collection/>" id "/tiles") {:as :json :query-params {:format "json" :key (env :key)}}

roelofw 2016-12-08T18:17:11.000063Z

oke, I can do the same for the other urls , right ?

snoe 2016-12-08T18:17:16.000064Z

right, yeah

roelofw 2016-12-08T18:17:25.000065Z

thanks, I will try it

snoe 2016-12-08T18:18:22.000066Z

the rest is pretty good for a first project. I'd look into your editor and find a way to auto-format removing extra spaces and trailing parens

roelofw 2016-12-08T18:21:05.000067Z

changed it and will try to build it

roelofw 2016-12-08T18:21:59.000068Z

and it worked

roelofw 2016-12-08T18:22:14.000069Z

now I will change the rest and update my repo

roelofw 2016-12-08T18:22:44.000070Z

@snoe : thanks for the remarks , so I learn more and more about clojure

snoe 2016-12-08T18:34:17.000071Z

@roelofw you might also want to look at http-kit over clj-http http://stackoverflow.com/a/21473485 depends how many ids you're doing in parallel.

roelofw 2016-12-08T18:34:53.000073Z

moment, one problem at the time

snoe 2016-12-08T18:35:29.000074Z

I'm not suggesting you do, just know it's available

roelofw 2016-12-08T18:35:32.000075Z

@snoe : can you see if I made a error here :

( str "<https://www.rijksmuseum.nl/api/nl/collection?>")
                 (client/get {:as :json :query-params {:key (env :key) :format "json" :type "schilderijen" :toppieces "True"}}) 

snoe 2016-12-08T18:35:40.000076Z

drop the ?

roelofw 2016-12-08T18:35:42.000077Z

Ì see now a empty output

roelofw 2016-12-08T18:36:39.000078Z

oke, I changed it and try again

roelofw 2016-12-08T18:39:51.000079Z

hmm, still empty output

snoe 2016-12-08T18:43:36.000080Z

type=schilderij vs {:type "schilderijen"} ?

roelofw 2016-12-08T18:46:12.000081Z

@snoe : you mean like this : (client/get {:as :json :query-params {:key (env :key) :format "json" "type=schilderijen" :toppieces "True"}})

roelofw 2016-12-08T18:46:58.000082Z

nope, I see then a error message

snoe 2016-12-08T18:49:03.000083Z

no, in github you didn't have the en at the end of the value

snoe 2016-12-08T18:50:10.000084Z

you were using schilderij / but you just pasted schilderijen

roelofw 2016-12-08T18:58:43.000085Z

oke, I did things too fast

roelofw 2016-12-08T18:58:48.000086Z

I will change it

roelofw 2016-12-08T19:00:23.000087Z

thanks, that worked well

roelofw 2016-12-08T19:01:10.000088Z

@snoe , Do you want to see the new code ?

snoe 2016-12-08T19:03:44.000089Z

sounds like you got it, but I did notice this last pmap should probably be a map https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj#L54 because merge is so fast

roelofw 2016-12-08T19:04:09.000091Z

oke, I can change that also

roelofw 2016-12-08T19:04:58.000092Z

and the maxium api calls that run in parallel are 10

roelofw 2016-12-08T19:05:24.000093Z

IM looking at http-kit and try to figure out how to change the code t

snoe 2016-12-08T19:05:48.000094Z

if the max is 10, i'd stick with clj-http

roelofw 2016-12-08T19:06:50.000095Z

oke

roelofw 2016-12-08T19:06:58.000096Z

Thanks for all the remarks

snoe 2016-12-08T19:07:05.000097Z

no problem

roelofw 2016-12-08T19:13:04.000098Z

and here the changed code with your name mentioned : https://github.com/rwobben/paintings

👍 1
roelofw 2016-12-08T19:13:07.000100Z

@snoe

snoe 2016-12-08T19:17:52.000103Z

@roelofw

roelofw 2016-12-08T19:41:12.000104Z

you can be right, I takes a map and returns a map

roelofw 2016-12-08T19:41:24.000105Z

I have to rewrite it then

roelofw 2016-12-08T19:42:20.000106Z

the only thing I have to figure out is how to deal with 2 variables result and id.

roelofw 2016-12-08T19:42:42.000107Z

as far as I know map can only take a anymous function with 1 parameter

roelofw 2016-12-08T19:47:42.000108Z

What happens is that I have a id of this type : NL-SK-C-5 and I need this SK-C-5

roelofw 2016-12-08T19:49:19.000109Z

so I can do (map (fn [item] (subs id 3) )

roelofw 2016-12-08T19:50:40.000111Z

@snoe

snoe 2016-12-08T19:52:56.000113Z

results is just the intermediate vector you're building up inside the reduce right?

snoe 2016-12-08T19:53:20.000114Z

I think you're close with that map

roelofw 2016-12-08T19:53:36.000115Z

yes, as I see it result is the accumelator

roelofw 2016-12-08T19:53:56.000116Z

I think also, Im only afraid I loose the rest of the map

snoe 2016-12-08T19:56:59.000117Z

how's that? map-id is the list of the NL- prefixed ids and you want to subs each one.

snoe 2016-12-08T19:59:26.000118Z

you can do almost anything to a list with reduce, map filter etc are just a level of abstraction above. especially when learning clojure if you ever feel the need to use reduce first look through clojure.core for a function that fits what you want to do more closely

roelofw 2016-12-08T20:02:02.000119Z

No the map looks like this { id: "NL-SK-C-5" : painter "Rembrandt" :year 1658 }

roelofw 2016-12-08T20:02:18.000120Z

and I only have to change the id and keep the rest

roelofw 2016-12-08T20:02:28.000121Z

or do we misunderstood each other

snoe 2016-12-08T20:06:31.000122Z

I'm pretty sure read-numbers is returning a vector of ids like ["SK-C-5"]

roelofw 2016-12-08T20:10:33.000124Z

you are right, Im confusing functions . Too late here to think well

roelofw 2016-12-08T20:16:01.000126Z

@snoe : I think this one is better (map (fn [item] (subs (:id item) 3) )

roelofw 2016-12-08T20:16:07.000127Z

I will try it

roelofw 2016-12-08T20:26:00.000128Z

hmm, that gives a empty seq , even as (map (fn [item] (subs item) 3 ) [] map-id)]

gdeer81 2016-12-08T20:28:40.000129Z

in read-numbers, how are you able to use the :artObjects key when the body is a json string?

gdeer81 2016-12-08T20:38:55.000130Z

I also noticed in the json response that there is a key called "objectNumber" that is exactly what you're trying to get when you substring the id

roelofw 2016-12-08T20:39:29.000131Z

Because client/get { :as json}) convert the json to a clojure object

gdeer81 2016-12-08T20:45:55.000132Z

that's odd, it's not doing that at the repl

gdeer81 2016-12-08T20:47:36.000133Z

might be because I'm bypassing the middle layer wrappers at the repl

roelofw 2016-12-08T20:48:27.000134Z

can be map-id looks like this:

("nl-SK-A-2963"
 "nl-SK-C-2"
 "nl-SK-C-149"
 "nl-SK-A-3841"
 "nl-SK-C-1368"
 "nl-SK-A-1718"
 "nl-SK-A-1115"
 "nl-SK-A-799"
 "nl-SK-A-3584"
 "nl-SK-A-2860") 

roelofw 2016-12-08T20:51:12.000135Z

oke, this one works (map (fn [item] (subs item 3 )) map-id)

roelofw 2016-12-08T20:53:07.000138Z

@snoe : does this look well or can I improve it

roelofw 2016-12-08T20:53:53.000139Z

@gdeer81 what output do you get from read-numbers then ?

gdeer81 2016-12-08T20:57:36.000140Z

at the repl you get json. I was pulling out the object numbers with (re-seq #"SK-[A-Z]-[0-9]{0, 4}" body-of-response)

roelofw 2016-12-08T20:58:46.000142Z

json respons from this

( str "<https://www.rijksmuseum.nl/api/nl/collection>")
                 (client/get {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True"}})  

roelofw 2016-12-08T20:58:55.000143Z

that is very wierd

gdeer81 2016-12-08T21:00:14.000144Z

also, I'm running a bare repl with only clj-http as a dep, I'm not running it from the project

gdeer81 2016-12-08T21:00:50.000145Z

side note, why are you calling str when you only have one string?

roelofw 2016-12-08T21:01:27.000147Z

o, that is a left over from another remark

roelofw 2016-12-08T21:02:15.000149Z

I think I can delete that

gdeer81 2016-12-08T21:02:57.000150Z

okay, I see where you're concating the id. wow the codebase keeps mutating out from under me lol

roelofw 2016-12-08T21:03:30.000151Z

yes, that is for me the learning process

roelofw 2016-12-08T21:03:47.000152Z

learn how I can do things "better"

roelofw 2016-12-08T21:13:49.000159Z

@gdeer81 this better :

(defn read-numbers
  "Reads the ids of the paintings"
  []
  (let [data (-&gt; (client/get  "<https://www.rijksmuseum.nl/api/nl/collection>" {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True"}})
                 :body
                 :artObjects
                 )
        map-id (map :id data)
        ids (map (fn [item] (subs item 3 )) map-id) ]
    ids )) 

2016-12-08T21:15:04.000160Z

:as :json is dependent on the cheshire library being present

gdeer81 2016-12-08T21:21:34.000163Z

@hiredman thank you. Okay I spun up my repl with lein try "clj-http" "cheshire" and it gave me enough dependencies to test the function

gdeer81 2016-12-08T21:30:18.000164Z

@roelofw Spoiler alert, you can do all of that with (-&gt;&gt; (client/get "<https://www.rijksmuseum.nl/api/nl/collection>" {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True"}}) :body :artObjects (map :objectNumber))

2016-12-08T21:31:11.000165Z

you can lose the partial and use ->>

gdeer81 2016-12-08T21:32:37.000167Z

okay, updated the snippet

roelofw 2016-12-08T21:49:02.000168Z

@gdeer81 oke, and object-number is the number without the NL part ?

roelofw 2016-12-08T21:49:56.000169Z

and can I make test for testing all functions

roelofw 2016-12-08T21:50:14.000170Z

I did that is not going to work because of the external api

roelofw 2016-12-08T22:09:01.000171Z

@gdeer81 yes, this is also working :

(defn read-numbers
  "Reads the ids of the paintings"
  []
  (-&gt;&gt; (client/get  "<https://www.rijksmuseum.nl/api/nl/collection>" {:as :json :query-params {:key (env :key) :format "json" :type "schilderij" :toppieces "True"}})
                 :body
                 :artObjects
                 (map :objectNumber)))  

roelofw 2016-12-08T22:09:17.000172Z

the code gets shorter and shorter

roelofw 2016-12-08T22:09:24.000173Z

Time to sleep now

roelofw 2016-12-08T22:09:31.000174Z

Thanks all

gdeer81 2016-12-08T22:10:02.000175Z

until next time

roelofw 2016-12-08T22:11:37.000176Z

if you have other remarks , write them down here or make a issue

roelofw 2016-12-08T22:11:57.000177Z

Have a good day, @gdeer81

gdeer81 2016-12-08T22:12:23.000178Z

will do