Currently, my rss script generates a rss feed for a website using an API. It worked until I forgot that some special characters aren’t allowed in xml format. What is the best way to get rid of or escape the & symbol?

Here’s the code:

import requests
import os

def generate_rss(data):
    rss = """\
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

<title>ComicK - RSS Feed</title>
<description>A simple RSS feed for ComicK!</description>

    for i in data:
        c = i["md_comics"]

        rss += """\
            f"{c['title']} - Chapter {i['chap']}",
            f"Chapter {i['chap']} of {c['title']} is now available on ComicK!",

    rss += "\n</channel>\n</rss>"
    return rss

url = ""
data = requests.get(url).json()

filename = f"./comick/comick-rss-nsfw.xml"

os.makedirs(os.path.dirname(filename), exist_ok=True)

with open(filename, "w", encoding="utf-8") as f_out:
    print(generate_rss(data), file=f_out)

I think it would have to be put into a list, but then I am not entirely sure if it would still be the same.

Source link

By Ajay Kumar Verma

techopenion is the one stop solution of all your information needs. Get everything from latest tech updates to latest gadgets in technology.

Leave a Reply

Your email address will not be published. Required fields are marked *