python rss feed generator giving wrong format

  flask, python, rss

i’m trying to render a playexample of an rss-feed for my flask application.
I have the following code:

from flask import Flask, render_template, flash, redirect, make_response
from config import Config
from feedgen.feed import FeedGenerator
app = Flask(__name__)
 strengs = ["noget", "lorem ipsum", "dingledongle"]
 @app.route('/xml2')
def xml2():
    fg = FeedGenerator()
    fg.title('Feed title')
    fg.description('Feed description')
    fg.link(href='https://awesome.com')

    f = open("xss.txt", "r")

    n = 0 

    for i in strengs:

        ns = str(n)

        fe = fg.add_entry()
        fe.title("hi")
        fe.link(href="dr.dk")
        print(i)
        fe.description(i)
        fe.guid(ns, permalink=False) # Or: fe.guid(article.url, permalink=True)
        fe.author(name="garse", email="[email protected]")
        n = n + 1

    response = make_response(fg.rss_str())
    response.headers.set('Content-Type', 'application/rss+xml')

    return response

So I just wanna render a rss feed with 3 articles with these 3 strings in them. The xml file rendered looks correct to me:

<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Feed title</title><link>https://awesome.com</link><description>Feed description</description><docs>http://www.rssboard.org/rss-specification</docs><generator>python-feedgen</generator><lastBuildDate>Thu, 08 Apr 2021 14:55:38 +0000</lastBuildDate><item><title>hi</title><link>dr.dk</link><description>dingledongle</description><author>[email protected] (garse)</author><guid isPermaLink="false">2</guid></item><item><title>hi</title><link>dr.dk</link><description>lorem ipsum</description><author>[email protected] (garse)</author><guid isPermaLink="false">1</guid></item><item><title>hi</title><link>dr.dk</link><description>noget</description><author>[email protected] (garse)</author><guid isPermaLink="false">0</guid></item></channel></rss>

But when I then make my rss-reader (raven reader) read this xml file, it only generates one single article Where only the first article is shown, the with the "noget" description.

How do I render several articles in my rss feed? am I doing something wrong here?

Source: Python Questions

LEAVE A COMMENT