46 lines
1.7 KiB
Common Lisp
46 lines
1.7 KiB
Common Lisp
(in-package :lispostory)
|
|
|
|
(define-data-source mob)
|
|
|
|
(defparameter *maplestory-mobs-url* "https://maplestory.io/api/gms/83/mob")
|
|
|
|
(defun get-maplestory-mobs ()
|
|
(http-get-json *maplestory-mobs-url*))
|
|
|
|
(defparameter *chronostory-mob-url-format* "https://chronostory.onrender.com/api/mob-info?mobId=~a")
|
|
(defparameter *chronostory-mob-drop-url-format* "https://chronostory.onrender.com/api/mob-drops?mobId=~a")
|
|
|
|
(defun chronostory-mob-url (mob-id)
|
|
(format nil *chronostory-mob-url-format* mob-id))
|
|
|
|
(defun get-chrono-mob (maple-mob)
|
|
(let* ((mob-id (gethash "id" maple-mob))
|
|
(url (chronostory-mob-url mob-id))
|
|
(data (http-get-json url)))
|
|
(sleep 0.3)
|
|
(when data
|
|
(uiop:println (concatenate 'string "Retrieved id " (write-to-string mob-id))))
|
|
data))
|
|
|
|
(defmethod refresh ((ds mob-data-source))
|
|
(let* ((maple-mobs (get-maplestory-mobs))
|
|
(_ (uiop:println "Retrieved maplestory mobs. Getting chronostory mobs..."))
|
|
(chrono-mobs
|
|
(loop for maple-mob across maple-mobs
|
|
for chrono-mob = (get-chrono-mob maple-mob)
|
|
when (let ((mob (and chrono-mob (gethash "mob" chrono-mob))))
|
|
(and mob
|
|
(numberp (gethash "released" mob))
|
|
(= (gethash "released" mob) 1)))
|
|
collect chrono-mob))
|
|
(chrono-mobs-str (shasht:write-json chrono-mobs nil)))
|
|
(declare (ignore _))
|
|
(uiop:println "Retrieved chronostory mobs. Writing out to json file...")
|
|
(setf (cache ds) chrono-mobs)
|
|
(write-string-into-file chrono-mobs-str (file-path ds) :if-exists :overwrite :if-does-not-exist :create)
|
|
(uiop:println "Done!")))
|
|
|
|
(comment
|
|
(defvar mobs (make-mob-data-source nil))
|
|
(reload mobs))
|