45 lines
1.6 KiB
Common Lisp
45 lines
1.6 KiB
Common Lisp
(in-package :lispostory)
|
|
|
|
(define-data-source item)
|
|
|
|
(defparameter *maplestory-items-url* "https://maplestory.io/api/gms/83/item")
|
|
|
|
(defun get-maplestory-items ()
|
|
(http-get-json *maplestory-items-url*))
|
|
|
|
(defparameter *chronostory-item-url-format* "https://chronostory.onrender.com/api/item-info?itemId=~a")
|
|
|
|
(defun chronostory-item-url (item-id)
|
|
(format nil *chronostory-item-url-format* item-id))
|
|
|
|
(defun get-chrono-item (maple-item)
|
|
(if (gethash "isCash" maple-item)
|
|
nil
|
|
(let* ((item-id (gethash "id" maple-item))
|
|
(url (chronostory-item-url item-id))
|
|
(data (http-get-json url)))
|
|
(sleep 0.3)
|
|
(when data
|
|
(uiop:println (concatenate 'string "Retrieved id " (write-to-string item-id))))
|
|
data)))
|
|
|
|
(defmethod refresh ((ds item-data-source))
|
|
(let* ((maple-items (get-maplestory-items))
|
|
(_ (uiop:println "Retrieved maplestory items. Getting chronostory items..."))
|
|
(chrono-items
|
|
(loop for maple-item across maple-items
|
|
for chrono-item = (get-chrono-item maple-item)
|
|
when (and chrono-item
|
|
(stringp (gethash "item_name" chrono-item))
|
|
(string-not-equal (gethash "item_name" chrono-item) ""))
|
|
collect chrono-item)))
|
|
(declare (ignore _))
|
|
(uiop:println "Retrieved chronostory items. Writing out to json file...")
|
|
(setf (cache ds) chrono-items)
|
|
(write-string-into-file
|
|
(shasht:write-json chrono-items nil)
|
|
(file-path ds)
|
|
:if-exists :overwrite
|
|
:if-does-not-exist :create)
|
|
(uiop:println "Done!")))
|