18 August 2010

This tutorial shows how to make RSS feeds in Python for Google App Engine.

This is actually really simple because I am using pre made library PyRSS2Gen.

Manual RSS Feeds(basic stuff to work):

Get the rss library and put PyRSS2Gen.py file in your project folder. I am using lib folder for all of my external libraries.

Basic stuff to work:

This is my file structure:
Source code viewer
  1. /
  2. /controllers/rss.py
  3. /libs/__init__.py
  4. /libs/PyRSS2Gen.py
  5. /app.yaml
Programming Language: Text
The init file in libs folder is necessary, otherwise the library won't work.

This is my app.yaml file:
Source code viewer
  1. application: project-name
  2. version: 1
  3. runtime: python
  4. api_version: 1
  5.  
  6. handlers:
  7. - url: /rss.xml
  8.   script: controllers/rss.py
  9. - url: /static
  10.   static_dir: static
Programming Language: YAML
As you can see we will get our RSS code by going to http://your-project.appspot.com/rss.xml.

This is the RSS code generator, rss.py:
Source code viewer
  1. import datetime
  2. from libs import PyRSS2Gen
  3.  
  4. rss = PyRSS2Gen.RSS2(
  5. title = "Test feed",
  6. link = "http://www.browse-tutorials.net/",
  7. description = "RSS Description",
  8.  
  9. lastBuildDate = datetime.datetime.now(),
  10.  
  11. items = [
  12. PyRSS2Gen.RSSItem(
  13. title = "Feed 1",
  14. link = "http://www.browse-tutorials.net/tutorial/...",
  15. description = "RSS 1 Description",
  16. guid = PyRSS2Gen.Guid("guid1"),
  17. pubDate = datetime.datetime(2010, 9, 6, 21, 31)),
  18. PyRSS2Gen.RSSItem(
  19. title = "Feed 2",
  20. link = "http://www.browse-tutorials.net/tutorial/..."
  21. "archive/2003/09/06/RSS.html",
  22. description = "RSS 1 Description",
  23. guid = PyRSS2Gen.Guid("guid2"),
  24. pubDate = datetime.datetime(2010, 9, 6, 21, 49)),
  25. ])
  26.  
  27. print 'Content-Type: text/xml'
  28. print rss.to_xml()
Programming Language: Python
The simplest way to make this happen.
That's how you make RSS code in Google App Engine. This is really basic. Of course you can take the data from datastore and use foreach to populate the RSS array.