Skip to main content

A Django app using feedparser to fetch and parse a feed to render it from a template.

Project description

A Django app using feedparser to fetch and parse a feed to render it from a template.

It is not a Feed agregator since it manage feeds one by one.

  • requests is used to fetch feeds;

  • feedparser is used to parse feeds;

  • Django cache is used to avoid fetching again the feed each time;

  • Basic feed renderers just parse the feed without modifying anything but you can extend it to implement your post-process formatting;

  • Once the feed has been fetched, it can be displayed through a template. Default template is really basic and you should eventually override it or create another one to fit to your feed structure/format;

  • A DjangoCMS plugin is available on cmsplugin_feedparser;

Imagescape Fork

This fork has been modified to: * Pass the request context into the inclusion tag * Allow for normal app settings behavior * Add a template filter, feed_date, for converting dates into datetime objects

Requires

Install

First install the package:

pip install django3-feedparser

Add it to your installed Django apps in settings:

INSTALLED_APPS = (
    ...
    'django_feedparser',
    ...
)

Then import its settings:

from django_feedparser.settings import *

And finally see about Available settings you can override.

Usage

Renderers

There is actually two basic renderer available:

basic-xml

Just the basic renderer, parsing an XML feed and return result given by feedparser.

Don’t do any special formatting.

basic-json

Like basic-xml but for a JSON feed, obviously don’t use feedparser but the json builtin from Python and return the loaded object.

Finally, remember than your renderer have to be compatible with the used template and vice-versa.

Views

There is a mixin django_feedparser.views.FeedFetchMixin you can inherit from your views to exploit a feed.

And there is a basic view django_feedparser.views.FeedView that inherits from mixin FeedFetchMixin to demonstrate its usage. However the basic view is usable as it if it meets your needing, if so you just have to use it directly in your urls like django.views.generic.base.TemplateView:

from django.conf.urls import *

from .views import FeedView

urlpatterns = patterns('',
    ...
    url(r'^myfeed/$', FeedView.as_view(feed_url="http://localhost/myfeed.xml"), name="myfeed"),
    ...
)

Template tags

More common way is to use the template tag to include rendered feed in your templates.

Basic sample:

{% load feedparser_tags %}
{% feedparser_render 'http://localhost/sample.xml' %}

Or with all accepted arguments:

{% feedparser_render 'http://localhost/sample.xml' renderer='CustomRenderer' template='foo/custom.html' expiration=3600 %}

Available settings

FEED_RENDERER_DEFAULT_TEMPLATE

Path to the default renderer template.

Default value: 'django_feedparser/basic_feed_renderer.html'

FEED_CACHE_KEY

Feed cache key template string.

Default value: 'feedparser_feed_{id}_{expire}'

FEED_TIMEOUT

Timeout until feed response, in seconds.

Default value: 5

FEED_BOZO_ACCEPT

Wether we accept (True) badly formatted xml feed or not (False).

Default value: True

FEED_SAFE_FETCHING

Wether fetching a feed throw an exception (False) or not (True).

Bad http status, request errors and timeout error are silently catched when safe fetching is enabled.

Default value: False

FEED_RENDER_ENGINES

A Python dictionnary for available renderer engines, where the key is the shortcut engine name and the value is a valid Python path to the renderer class.

Default value:

{
    'basic-xml': 'django_feedparser.renderer.FeedBasicRenderer',
    'basic-json': 'django_feedparser.renderer.FeedBasicRenderer',
}
DEFAULT_FEED_RENDER_ENGINE

The default renderer engine name to use when no one is given.

Default value: basic-xml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django3-feedparser-2.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django3_feedparser-2.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file django3-feedparser-2.0.1.tar.gz.

File metadata

  • Download URL: django3-feedparser-2.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.4.0-117-generic

File hashes

Hashes for django3-feedparser-2.0.1.tar.gz
Algorithm Hash digest
SHA256 cd3b94d8c3bf105ab79f100917a4cb219f3351f6556db7b31c4d7fe32835c7af
MD5 9ecf96c0b871b53ffd77a442ef7b01e2
BLAKE2b-256 3dfd8a565da7cd69b6048c6ffd63460ea2cf86bf96e1b807069c5bcb725fa4c2

See more details on using hashes here.

File details

Details for the file django3_feedparser-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: django3_feedparser-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.4.0-117-generic

File hashes

Hashes for django3_feedparser-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66c9d59c5695bcdf47fd2529d12513192a181fe48d99de0d4fe59a5687c03f77
MD5 eee37b4efc5ce1c2785f5c569fe9ba65
BLAKE2b-256 9997cffd2b4f7364add9fac0632117eda2afe9108f7684b11e31fbc8a6dba7ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page