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 renderer 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;
Links
Download his PyPi package;
Clone it on his repository;
Requires
Django >= 1.4;
requests >= 2.7.0’,
feedparser >= 5.1.3’,
Install
First install the package:
pip install django-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 your can override.
Usage
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"), ... )
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 bad http status or request error will throw an exception (False) or not (True).
Default value: True
- 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': 'django_feedparser.renderer.FeedBasicRenderer', }
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.