|
|
@@ -54,6 +54,8 @@ is replaced with replacement."
|
|
|
"Append together elements (or lists) in the list."
|
|
|
(mappend #'(lambda (x) (if (listp x) (flatten x) (list x))) the-list))
|
|
|
|
|
|
+
|
|
|
+;; Circular lists
|
|
|
(defun make-circular (items)
|
|
|
"Make items list circular"
|
|
|
(setf (cdr (last items)) items))
|
|
|
@@ -81,6 +83,43 @@ is replaced with replacement."
|
|
|
(nreverse (push (car cur) result)))
|
|
|
(push (car cur) result)))
|
|
|
|
|
|
+(defun http-default (url)
|
|
|
+ (let ((uri (puri:uri url)))
|
|
|
+ (puri:render-uri
|
|
|
+ (if (null (puri:uri-scheme uri))
|
|
|
+ (puri:uri (format nil "http://~A" url))
|
|
|
+ uri)
|
|
|
+ nil)))
|
|
|
+
|
|
|
+;; XML processing
|
|
|
+(defun xml-request (url)
|
|
|
+ (multiple-value-bind (http-stream status headers uri stream)
|
|
|
+ (drakma:http-request (http-default url)
|
|
|
+ :force-binary t
|
|
|
+ :want-stream t
|
|
|
+ :decode-content t)
|
|
|
+ (declare (ignore status headers stream))
|
|
|
+ (unwind-protect
|
|
|
+ (progn
|
|
|
+ (setf (flex:flexi-stream-external-format http-stream) :utf-8)
|
|
|
+ (values (plump:parse http-stream) uri))
|
|
|
+ (ignore-errors (close http-stream)))))
|
|
|
+
|
|
|
+(defun get-by-tag (node tag)
|
|
|
+ (nreverse (plump::get-elements-by-tag-name node tag)))
|
|
|
+
|
|
|
+;; JSON processing
|
|
|
+(defun json-request (url &key (method :get) parameters (object-as :alist))
|
|
|
+ (multiple-value-bind (http-stream status headers uri stream)
|
|
|
+ (drakma:http-request (http-default url) :method method :parameters parameters
|
|
|
+ :external-format-out :utf-8
|
|
|
+ :force-binary t :want-stream t :decode-content t)
|
|
|
+ (declare (ignore status headers stream))
|
|
|
+ (unwind-protect
|
|
|
+ (progn
|
|
|
+ (setf (flex:flexi-stream-external-format http-stream) :utf-8)
|
|
|
+ (values (yason:parse http-stream :object-as object-as) uri))
|
|
|
+ (ignore-errors (close http-stream)))))
|
|
|
|
|
|
;; Fix bug in local-time (following symlinks in /usr/share/zoneinfo/
|
|
|
;; leads to bad cutoff)
|