[Django]-Generating simple RSS feed from parsed data

6đź‘Ť

âś…

I noticed you have tagged your question as pertaining to Django. If you are going to build a Django application based on this problem, then the syndication framework is what you want to use. However, this isn’t worth it unless you are planning to use other components of Django, such as the database stuff and / or the template language.

However, you asked for the “simplest and easiest” solution. I love Django and it only takes me minutes to set up an app so for me the easiest way to do your whole project would probably be to make a quick Django app. The simplest solution is probably to create the feed manually, shouldn’t be that hard; something like:

inp="""System MA
user id =  2084
username =  XYZ90
selection =  pnq
decimal =  6.000
Percentage =  19.1176470588 %

System NA
user id =  2086
username =  pron1
selection =  abc
decimal =  13.000
Percentage =  13.1147540984 %

System M
user id =  1664
username =  Chrisod
selection =  pleader
decimal =  15.000
Percentage =  16.091954023 %"""

inp=inp.split('\n\n')

rss_start="""<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<channel>
  <title>Your title</title>
  <link>http://yoursite.com</link>
  <description>Your discription</description>
"""

rss_end="""</channel>

</rss> """

def description(item):
    return item

def title(item):
    return item.split('\n')[0]

def link(item):
    return 'http://mysite.com/' + item.split('\n')[0]

rss_items=[]
for counter, item in enumerate(inp):
    rss_items.append("""
  <item>
    <title>%s</title>
    <link>%s</link>
    <description>%s</description>
    <guid>counter</guid>
  </item>""" % (title(item),description(item),link(item)))

rss_output=rss_start+''.join(rss_items)+rss_end

You probably also want to add <pubDate> tags. And make sure your <guid>s are unique.

Note: rss template copied from w3schools.com

👤foobarbecue

Leave a comment