By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

RSS Feed Generator help

P: 11
I'm trying to make a basic RSS feed generator. I'm still a newb and I really need help. My aim is to have the user input all their desired settings then create an XML file in the same directory with all of their RSS settings.

First I'd like it to ask the user how many articles it wants to put in the RSS feed. So it can loop the adding articles bit that many times. Then after the user inputting all their desired options, for it to display, then save.

So far I have this, which is absolute rubbish. It looks horrendous and I think it is...How can I go about doing what I actually want to do?

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. print "Welcome please fill in these details about your websites feed:"
  3. name=raw_input("Name of Feed:")
  4. desc=raw_input("Description of Feed:")
  5. url=raw_input("Location of Website:")
  6. print "Your websites details have been temporarilly stored for this session, now fill in your articles details:"
  7. aname=raw_input("Name of Article to Syndicate:")
  8. adesc=raw_input("Description of Article to Syndicate:")
  9. aurl=raw_input("URL of Article:")
  10. print "Your article details have been filled in, please wait..."
  11. print "Your XML code for this Feed is:"
  12. print """<?xml version="1.0" encoding="ISO-8859-1" ?> \n
  13. <rss version="0.91">\n"""
  14. print """<channel>\n
  15. <title>"""
  16. print name
  17. print """</title> \n
  18. <link>"""
  19. print url
  20. print """</link>
  21. \n <description>"""
  22. print desc
  23. print """</description> \n
  24. <item><title>"""
  25. print aname
  26. print """</title">\n 
  27. <link>"""
  28. print aurl
  29. print """</link>\n <description>"""
  30. print adesc
  31. print """</description>\n
  32. </item>\n
  33. </channel>\n
  34. </rss>"""
Dec 23 '08 #1
Share this Question
Share on Google+
9 Replies

P: 144
you could export it to a file

another option would be to add a front end to the program with QT, gtk or something.
Dec 23 '08 #2

P: 11
I'm quite stuck on actually how to get all the settings inside the XML tags and then make it a variable it so I can export it. How can I do it?
Dec 23 '08 #3

P: 144
you could do something like this

Expand|Select|Wrap|Line Numbers
  1. file = open("output.xml","w");
  2. file.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>")
  3. file.write("<rss version=\"0.91\">\n<channel>\n<title>"+str(name)+"</title>");
  4. ...
Dec 23 '08 #4

P: 11
Thanks loads! :)
I shall do
Dec 23 '08 #5

P: 11
One more question, is there a command that can delete the contents of a chosen file
Dec 23 '08 #6

Expert Mod 2.5K+
P: 2,851
The following will effectively delete the contents of a disc file:
Expand|Select|Wrap|Line Numbers
  1. >>> f = open(file_name, 'w')
  2. >>> f.close()
Dec 23 '08 #7

Expert Mod 2.5K+
P: 2,851
You can compile a list of strings using string formatting and write them to file with one write statement. Example:
Expand|Select|Wrap|Line Numbers
  1. f = open(file_name, 'w')
  3. outlist = ['<?xml version="1.0" encoding="ISO-8859-1" ?>', '<rss version="0.91">',]
  4. outlist.append('  <channel>\n    <title>%s</title>' % name)
  5. outlist.append('    <link>%s</link>' % url)
  6. outlist.append('    <description>%s</description>' % desc)
  7. outlist.append('    <item>\n        <title>%s</title>' % aname)
  8. outlist.append('        <link>%s</link>' % aurl)
  9. outlist.append('        <description>%s</description>' % adesc)
  10. outlist.append('    </item>')
  11. outlist.append('  </channel>')
  12. outlist.append('</rss>')
  14. f.write('\n'.join(outlist))
  15. f.close()
Dec 23 '08 #8

P: 11
Thanks! This has really helped me :)
Dec 23 '08 #9

Expert Mod 2.5K+
P: 2,851
You are welcome, bhass. Thanks to micmast for contributing.

Dec 23 '08 #10

Post your reply

Sign in to post your reply or Sign up for a free account.