def include_feed(feed_url, *args):
feed = feedparser.parse(feed_url)<EOL>items = []<EOL>if len(args) == <NUM_LIT:2>:<EOL><INDENT>num_items, template_name = args<EOL><DEDENT>elif len(args) == <NUM_LIT:1>:<EOL><INDENT>num_items, template_name = None, args[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>num_items = int(num_items) or len(feed['<STR_LIT>'])<EOL>for i in range(num_items):<EOL><INDENT>pub_date = feed['<STR_LIT>'][i].updated_parsed<EOL>published = datetime.date(pub_date[<NUM_LIT:0>], pub_date[<NUM_LIT:1>], pub_date[<NUM_LIT:2>])<EOL>items.append({ '<STR_LIT:title>': feed['<STR_LIT>'][i].title,<EOL>'<STR_LIT>': feed['<STR_LIT>'][i].summary,<EOL>'<STR_LIT>': feed['<STR_LIT>'][i].link,<EOL>'<STR_LIT:date>': published })<EOL><DEDENT>return template_name, { '<STR_LIT>': items, '<STR_LIT>': feed }<EOL>
Parse an RSS or Atom feed and render a given number of its items
into HTML.

It is **highly** recommended that you use `Django's template
fragment caching`_ to cache the output of this tag for a
reasonable amount of time (e.g., one hour); polling a feed too
often is impolite, wastes bandwidth and may lead to the feed
provider banning your IP address.

.. _Django's template fragment caching: http://www.djangoproject.com/documentation/cache/#template-fragment-caching

Arguments should be:

1. The URL of the feed to parse.

2. The name of a template to use for rendering the results into HTML.

3. The number of items to render (if not supplied, renders all
   items in the feed).

The template used to render the results will receive two variables:

``items``
    A list of dictionaries representing feed items, each with
    'title', 'summary', 'link' and 'date' members.

``feed``
    The feed itself, for pulling out arbitrary attributes.

Requires the Universal Feed Parser, which can be obtained at
http://feedparser.org/. See `its documentation`_ for details of the
parsed feed object.

.. _its documentation: http://feedparser.org/docs/

Syntax::

    {% include_feed [feed_url] [num_items] [template_name] %}

Example::

    {% include_feed "http://www2.ljworld.com/rss/headlines/" 10 feed_includes/ljworld_headlines.html %}