initial commit
This commit is contained in:
54
items.lisp
Normal file
54
items.lisp
Normal file
@@ -0,0 +1,54 @@
|
||||
(in-package :lispostory)
|
||||
|
||||
(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")
|
||||
|
||||
(defparameter *chronostory-items* (make-array 0))
|
||||
|
||||
(defun chronostory-item-url (item-id)
|
||||
(format nil *chronostory-item-url-format* item-id))
|
||||
|
||||
(defun reload-item-data ()
|
||||
(let ((item-data (shasht:read-json (uiop:read-file-string "items.json"))))
|
||||
(setf *chronostory-items* item-data)
|
||||
item-data))
|
||||
|
||||
(defun load-item-data ()
|
||||
(if (/= (length *chronostory-items*) 0)
|
||||
*chronostory-items*
|
||||
(reload-item-data)))
|
||||
|
||||
(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)))
|
||||
|
||||
(defun refresh-item-data ()
|
||||
(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 *chronostory-items* chrono-items)
|
||||
(alexandria-2:write-string-into-file
|
||||
(shasht:write-json chrono-items nil)
|
||||
"items.json"
|
||||
:if-exists :overwrite
|
||||
:if-does-not-exist :create)
|
||||
(uiop:println "Done!")))
|
||||
Reference in New Issue
Block a user