Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.2KB

  1. #|
  2. scryfall API parser
  3. WIP
  4. This downloads the API data. We haven't even parsed that data
  5. yet. It's hundreds of GB.
  6. |#
  7. (in-package #:cl-user)
  8. (defpackage #:cl-deck-builder2.models.mtg
  9. (:use :cl))
  10. (in-package #:cl-deck-builder2.models.mtg)
  11. (defparameter *base-scryfall-api-uri* "https://api.scryfall.com/")
  12. (defun scryfall-api-uri (path)
  13. (format nil "~a~a" *base-scryfall-api-uri* path))
  14. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  15. (defvar *scryfall-api-data* nil
  16. "A list of SCRYFALL-API-DATA objects.")
  17. (defclass scryfall-api-data ()
  18. ((|content_encoding| :accessor scryfall-content-encoding :initarg :|content_encoding|)
  19. (|content_type| :accessor scryfall-content-type :initarg :|content_type|)
  20. (|description| :accessor scryfall-description :initarg :|description|)
  21. (|download_uri| :accessor scryfall-download-uri :initarg :|download_uri|)
  22. (|id| :accessor scryfall-id :initarg :|id|)
  23. (|name| :accessor scryfall-name :initarg :|name|)
  24. (|object| :accessor scryfall-object :initarg :|object|)
  25. (|size| :accessor scryfall-size :initarg :|size|)
  26. (|type| :accessor scryfall-type :initarg :|type|)
  27. (|updated_at| :accessor scryfall-updated-at :initarg :|updated_at|)
  28. (|uri| :accessor scryfall-uri :initarg :|uri|)))
  29. (defun get-scryfall-data ()
  30. (let ((json (getf
  31. (jonathan:parse
  32. (flex:octets-to-string
  33. (drakma:http-request (scryfall-api-uri "bulk-data"))))
  34. :|data|)))
  35. (mapcar (lambda (row)
  36. (apply #'make-instance 'scryfall-api-data row))
  37. json)))
  38. (defun load-scryfall-data ()
  39. (setf *scryfall-api-data*
  40. (get-scryfall-data)))
  41. (defun size-in-gb (size)
  42. (float (/ size (* 1024 1024 1024))))
  43. (defun get-bulk-data-uris (path)
  44. (with-open-file (out path
  45. :direction :output
  46. :if-exists :supersede
  47. :if-does-not-exist :create)
  48. (format out "~{~A~%~}"
  49. (mapcar #'scryfall-download-uri *scryfall-api-data*))))