PasteRack.org
Paste # 22472
2022-05-17 23:45:47

Fork as a new paste.

Paste viewed 1358 times.


Embed:

  1. #lang racket
  2.  
  3. (require net/url
  4.          racket/draw
  5.          json
  6.          threading)
  7.  
  8. (define (get-json url)
  9.   (call/input-url url get-pure-port read-json))
  10.  
  11. (define (get-image url)
  12.   (call/input-url url get-pure-port read-bitmap))
  13.  
  14. (define (set-search-url set)
  15.   (string->url (string-append "https://api.scryfall.com/cards/search?order=set&q=e%3A"
  16.                               set
  17.                               "&unique=prints")))
  18.  
  19. (define (get-set-cards set)
  20.   (let loop ([address (set-search-url set)]
  21.              [cards '()])
  22.     (let* ([resp (get-json address)]
  23.            [cards (append cards (hash-ref resp 'data))]
  24.            [has-more (hash-ref resp 'has_more)])
  25.       (if has-more
  26.           (loop (hash-ref resp 'next_page) cards)
  27.           cards))))
  28.  
  29. (define (display-cards-for-set set)
  30.   (map (λ~> (hash-ref 'image_uris)
  31.             (hash-ref 'small)
  32.             string->url
  33.             get-image)
  34.        (get-set-cards set)))
  35.  
  36. #;(display-cards-for-set "40k")

=>