Browse code
Cleanup fetching code a bit
fiddlerwoaroof authored on 05/04/2017 07:06:20
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -25,15 +25,8 @@ |
25 | 25 |
|
26 | 26 |
(defun fetch-doc-from-url (url) |
27 | 27 |
(setup-libraries-for-feeds |
28 |
- (loop |
|
29 |
- (restart-case (let ((data (drakma:http-request url :user-agent *user-agent*))) |
|
30 |
- (setup-libraries-for-feeds |
|
31 |
- (return (plump:parse data)))) |
|
32 |
- (retry () |
|
33 |
- :report (lambda (s) (format s "Retry fetching the feed ~a" url)) ) |
|
34 |
- (skip-feed () |
|
35 |
- (return) |
|
36 |
- :report (lambda (s) (format s "Skip fetching the url ~a" url))))))) |
|
28 |
+ (let ((data (drakma:http-request url :user-agent *user-agent*))) |
|
29 |
+ (plump:parse data)))) |
|
37 | 30 |
|
38 | 31 |
(define-condition fetch-error (error) ()) |
39 | 32 |
(define-condition feed-ambiguous (fetch-error) ((choices :initarg :choices :initform nil))) |
... | ... |
@@ -74,9 +67,18 @@ |
74 | 67 |
:report (lambda (s) (format s "Provide a function to select the right feed")) |
75 | 68 |
(find-if selector feeds))))))))) |
76 | 69 |
|
70 |
+(defmacro with-retry ((retry-message &rest args) action &body other-restarts) |
|
71 |
+ `(loop (restart-case (return ,action) |
|
72 |
+ (retry () |
|
73 |
+ :report (lambda (s) (format s ,retry-message ,@args))) |
|
74 |
+ ,@other-restarts))) |
|
75 |
+ |
|
77 | 76 |
(defun pull-feed (url &key detect type) |
78 |
- (to-feed |
|
79 |
- (if detect |
|
80 |
- (fetch-feed-from-url url) |
|
81 |
- (fetch-doc-from-url url)) |
|
82 |
- :type type)) |
|
77 |
+ (with-retry ("Retry fetching feed ~a" url) |
|
78 |
+ (to-feed |
|
79 |
+ (if detect |
|
80 |
+ (fetch-feed-from-url url) |
|
81 |
+ (fetch-doc-from-url url)) |
|
82 |
+ :type type) |
|
83 |
+ (skip-feed () (return) |
|
84 |
+ :report (lambda (s) (format s "Skip fetching feed ~a" url))))) |
... | ... |
@@ -37,6 +37,10 @@ |
37 | 37 |
(categories "category" :value (get-categories doc "> category")) |
38 | 38 |
source comments enclosure description) |
39 | 39 |
|
40 |
+;; TODO: finish the stuff necessary for rss->atom |
|
41 |
+(defmethod id ((object rss-feed)) |
|
42 |
+ (feed-link object)) |
|
43 |
+ |
|
40 | 44 |
(defmethod print-object ((self rss-image) stream) |
41 | 45 |
(print-unreadable-object (self stream :type t :identity t) |
42 | 46 |
(format stream "~a" (slot-value self 'url)))) |