38 lines
1.4 KiB
Common Lisp
38 lines
1.4 KiB
Common Lisp
(in-package :lispostory)
|
|
|
|
(define-data-source drop)
|
|
|
|
(defparameter *chronostory-drops-sheet-url* "https://docs.google.com/spreadsheets/d/e/2PACX-1vRpKuZGJQIFFxSi6kzYx4ALI0MQborpLEkh3J1qIGSd0Bw7U4NYg5CK-3ESzyK580z4D8NO59SUeC3k/pub?gid=1888753114&single=true&output=csv")
|
|
|
|
(defun cleanup-data (hm)
|
|
(dolist (key '("DropperID" "ItemID" "Chance" "MinQTY" "MaxQTY"))
|
|
(update-hash hm key (lambda (x) (string-replace-all "," x "")))
|
|
(update-hash hm key #'parse-integer))
|
|
(update-hash hm "AvgQty" #'parse-float)
|
|
(dolist (key '("isBoss" "Enable" "InGame"))
|
|
(update-hash hm key #'string->bool))
|
|
hm)
|
|
|
|
(defmethod refresh ((ds drop-data-source))
|
|
(let* ((data (drakma:http-request *chronostory-drops-sheet-url*))
|
|
(csv (cl-csv:read-csv data))
|
|
(header (car csv))
|
|
(num-fields-to-keep (position "" header :test #'equal))
|
|
(keys (mapcar #'string-to-hash-table-key (subseq header 0 num-fields-to-keep)))
|
|
(drops (map 'vector
|
|
(lambda (row)
|
|
(cleanup-data
|
|
(pairhash keys (subseq row 0 num-fields-to-keep) (dict))))
|
|
(cdr csv))))
|
|
(setf (cache ds) drops)
|
|
(write-string-into-file
|
|
(shasht:write-json drops nil)
|
|
(file-path ds)
|
|
:if-exists :overwrite
|
|
:if-does-not-exist :create)))
|
|
|
|
(comment
|
|
(defvar drops (make-drop-data-source "foo"))
|
|
(refresh drops)
|
|
(reload drops))
|