Fetching RSS Data With Code from ChatGPT

in #ai10 months ago (edited)

8ddtU87jbnOE82ktYY5C--1--mtdhb_2x.jpg

The above image was made with stable diffusion using the prompt 'javascript colorful.'

I get a little geeky sometimes. My latest diversion is creating a static page reading room populated by dynamic content from RSS feeds. It's a project I'm doing for fun on my own time, but it would rely on the RSS feeds provided by the news website I work for. My thinking is that some readers might find it useful to have the latest headlines from the site displayed in an information-dense manner, like conspiracy news at-a-glance.

Today at the coffee shop, I ran into a friend in tech and we talked all about it. My friend recommended using ChatGPT to generate the bare bones js needed to fetch and display the RSS items. This seemed like it was worth a try, so I spent a little while formulating my query and got this code back:

fetch('https://feeds.simplecast.com/54nAGcIl')
  .then(response => response.text())
  .then(data => {
    // Parse the XML data
    const parser = new DOMParser();
    const xmlDoc = parser.parseFromString(data, 'application/xml');

    // Access the items in the RSS feed
    const items = xmlDoc.querySelectorAll('item');

    // Process and display the first three items
    for (let i = 0; i < 3; i++) {
      if (i >= items.length) {
        break; // Stop the loop if there are fewer than three items
      }

      const item = items[i];
      const title = item.querySelector('title').textContent;
      const link = item.querySelector('link').textContent;

      // Create an HTML element for each item
      const itemElement = document.createElement('div');
      itemElement.innerHTML = `<a href="${link}">${title}</a>`;

      // Append the item element to the container
      const container = document.getElementById('rss-container');
      container.appendChild(itemElement);
    }
  })
  .catch(error => {
    console.error('Error:', error);
  });

When I tried it with a random popular RSS feed, this code worked. I was all set to put the reading room together, but my project hit a snag. The RSS url for the website I work for didn't return the expected items. It returned nothing, and I'd already tested the code I was using so that wasn't the problem.

The next time I talk to our tech guy, I'll bring it up and see what he says. Our RSS xml looks fine, I'm just not able to fetch it. The RSS url is https://www.wanttoknow.info/articles.xml?cid= which is weird because what does cid=? Using cid values of 1-25 produces xml pages of a few dozen articles each. The script I'm using couldn't fetch data from any cid value.

So my project is thwarted, at least temporarily. Oh well. And actually, the setback may turn out to be a good thing. I've been pushing for a news summaries json api that would make it easy to display news according to various complex formulas. If this api gets created, there'd be no reason to mess around anymore with RSS.

I've used ChatGPT to generate usable code snippets before and this latest episode worked out alright. The trick is in query formulation. I knew exactly what I wanted and how to describe this to the AI. I also verified that the code was functional by testing it before proceeding. There's a learning curve involved here that will only become steeper as the technology advances.

For now, people like my coffee shop friend are using ChatGPT to compensate for the ever-increasing pressure to do more with less. I feel like this is beginning to happen across industries, and no one really knows where it'll lead. How much code will be AI generated in 10 years? Maybe most.


Read my novels:

See my NFTs:

  • Small Gods of Time Travel is a 41 piece Tezos NFT collection on Objkt that goes with my book by the same name.
  • History and the Machine is a 20 piece Tezos NFT collection on Objkt based on my series of oil paintings of interesting people from history.
  • Artifacts of Mind Control is a 15 piece Tezos NFT collection on Objkt based on declassified CIA documents from the MKULTRA program.
Sort:  

Super interesting. Even though I just watched a few videos and read some articles about the RSS feed, I'm still kinda confused by what it is. But it should be interesting to hear what our tech guy has to say about all of this. :)

RSS is kinda obscure at this point but still useful for projects like this one. Guess we'll see what he says: )