Skip to content

Instantly share code, notes, and snippets.

@iemcd
Created January 14, 2024 00:55
Show Gist options
  • Save iemcd/fd1c7bff3b4f30137915378616460e66 to your computer and use it in GitHub Desktop.
Save iemcd/fd1c7bff3b4f30137915378616460e66 to your computer and use it in GitHub Desktop.

Use jquery xml to parse an opml file. (https://stackoverflow.com/questions/10943544/how-to-parse-an-rss-feed-using-javascript#10943610) Script:

  1. Read in opml. (Every page load?)
  2. Select a blog at random.
  3. Pull the most recent update to that blog.
<script src="jquery.js"></script>
<script>
$( document ).ready(function(){
    //Code
});
</script>

Parsing opml:

$.get(blogs.opml, function(data){
    $(data).find("outline").each( function() {
        var el = $(this);
        console.log(el.find("text").text()); // feed name
        // "type" is RSS or Atom
        // "xmlurl" and "htmlurl"
    });
});

Use .slice(n,n+1) to choose a random element. But now to choose n?

  • jquery doesn't "wrap" too-large indices Use .length property to get no. of elements?
    ots = $(data).find("outline");
    index = Math.floor(Math.random() * ots.length);
    feed = ots.slice(index, index + 1);

Then extract from the most recent element of the feed:

  • author
  • description or summary (RSS/atom)
  • link
  • pubDate or published (RSS/Atom)
  • title And from the feed itself:
  • feed name
  • type (internal)
  • url (internal?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment