PasteRack.org
Paste # 28093
2022-05-17 23:40:45

Fork as a new paste.

Paste viewed 1239 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. (map (λ~> (hash-ref 'image_uris)
  30.           (hash-ref 'small)
  31.           string->url
  32.           get-image)
  33.      (get-set-cards "40k"))

=>

tcp-connect: network access denied: '("api.scryfall.com" 443

client)