bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#64202: [PATCH] Gnus: Add back end for Atom feeds (nnatom)


From: Daniel Semyonov
Subject: bug#64202: [PATCH] Gnus: Add back end for Atom feeds (nnatom)
Date: Mon, 03 Jul 2023 03:00:14 +0300
User-agent: Gnus/5.13 (Gnus v5.13)

>>>>> Eric Abrahamsen writes:

    > Thanks again for working on this -- I'm getting around to trying
    > it out.  I have a dumb first question: how do I create a Atom
    > group? I wanted to try it out with the US weather.gov feed for my
    > state: https://alerts.weather.gov/cap/wa.php?x=0

    > I tried with "a" in the *Server* buffer, "G m" in the *Group*
    > buffer, but I guess neither allow for prompting the user for a
    > URL.

You can use "B nnatom RET <address> RET" in the group buffer for this
purpose.

    > I also added

    > (nnatom "alerts.weather.gov/cap/wa.php?x=0)

    > to my `gnus-secondary-select-methods' variable, but it said
    > "Server file alerts.weather.gov/cap/wa.php?x=0 not readable or
    > writable" when I restarted Gnus. I guess because we're going
    > straight to `nnatom-open-server', which reads a local file,
    > without ever fetching the file. We'd have to hit
    > `nnatom--parse-feed' to do that, but I don't see how we arrive
    > there without already having the server created.

The server should be allowed to open without an existing local file, as
long as that local file is writable, however...

    > What am I missing?

You're not missing anything, you actually just reminded me of a bug I
forgot to fix - the directory holding the local feed data isn't
automatically created if it's missing, which causes 'file-writable-p' to
return nil, preventing the server from opening.  As a workaround,
manually create an "atom" subdir under 'gnus-directory'.  I'll fix this
in the next version.

However, this particular feed still doesn't work since the comment at
the start of the feed changes the structure of the parsed representation
of the feed when libxml is supported (this also made me realize I
accidentally broke parsing without libxml in the last version, oops).
This is very useful info, as this is the first feed I encountered like
this, and I will fix both those issues too in the next version.

As a quick fix, redefine 'nnatom--read-feed' as:

(defun nnatom--read-feed (feed _)
  "Return a list structure representing FEED, or nil."
  (if (string-match-p "^https?://" feed)
      (nnheader-report
       nnatom-backend
       "Address shouldn't start with \"http://\"; or \"https://\"";)
    (with-temp-buffer
      (condition-case e
          (if (file-readable-p feed)
              (insert-file-contents feed)
            (mm-url-insert-file-contents (concat "https://"; feed)))
        (file-error (nnheader-report nnatom-backend (cdr e)))
        (:success (when-let ((data (if (libxml-available-p)
                                       (libxml-parse-xml-region
                                        (point-min) (point-max))
                                     (car (xml-parse-region
                                           (point-min) (point-max)))))
                             (auth (list 'authors)))
                    (when (eq (car data) 'top)
                      (setq data (assq 'feed data)))
                    (dom-add-child-before data auth)
                    (catch :stop ; Collect feed authors, stop at first entry.
                      (dolist (child (cdddr data) data)
                        (let ((tag (car-safe child)))
                          (if (eq tag 'entry)
                              (throw :stop data)
                            (and (or (eq tag 'author)
                                     (eq tag 'contributor))
                                 (dom-add-child-before auth child))))))))))))

Thanks,
Daniel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]