======
SubHub
======
SubHub is a Django application that implements a `PubSubHubBub`_ hub. Think
of it as a push mechanism that your personal site uses to notify subscribers
about changes in feeds that your site publishes.
.. note:: SubHub works only for Atom feeds. Which you should use anyway since
today there are no more reasons left to use actual RSS format for feeds.
This hub is not a standalone daemon that runs alongside your Django project.
It works as a library code sending notifications whenever you hit a "Publish"
button. It does, however, requires a cron job to process pending subscriptions
and failed notifications.
.. _PubSubHubBub: http://code.google.com/p/pubsubhubbub/
Installation
============
1. Install SubHub using your favorite package manager or simply with ``python
setup.py install``.
2. Include it "subhub" into INSTALLED_APPS in your Django settings and run
``./manage.py syncdb`` to create new tables.
3. Include SubHub urls into your project's urlconf under some sensible name::
urlpatterns = patterns('',
...
(r'^hub/', include('subhub.urls')),
)
4. Setup a cron job that will process pending subscriptions and distribute
failed notifications::
# Process subscriptions every 3 hours
0 */3 * * * user /path/to/manage.py subhub_maintenance --subscribe
# Distribute notifications every 15 minutes
*/15 * * * * user /path/to/manage.py subhub_maintenance --distribute
Announcing your hub
===================
In order to tell your potential subscribers that your feeds use PubSubHubBub
notifications you should include a link to a SubHub subscription view into
your Atom feeds. It looks a bit heavy but don't let it scare you off!
First thing to do is to subclass Django's built-in Atom feed generator and
teach it to look for hub links defined in your specific feed definitions::
from django.utils.feedgenerator import Atom1Feed
class HubAtom1Feed(Atom1Feed):
def add_root_elements(self, handler):
super(HubAtom1Feed, self).add_root_elements(handler)
hub_link = self.feed.get('hub_link')
if hub_link is not None:
handler.addQuickElement(u'link', '', {
u'rel': u'hub',
u'href': hub_link,
})
Then in each your feed for which you want to use notifications define a link::
from django.contrib.syndication import views
class MyBlogFeed(views.Feed):
feed_type = HubAtom1Feed
def feed_extra_kwargs(self, obj):
return {
'hub_link': absolute_url(reverse('subhub-hub')),
}
Chances are that you already have a function like ``absolute_url`` in your
project. It should make an URL absolute adding a scheme and a domain.
Publishing new and changed items
================================
To publish newly created or updated post you call function ``subhub.publish``
passing it two parameters:
- a list of feeds ("topics" in PubSubHubBub parlance) that this post appears in
- an entry_id for a post which in most cases is its absolute URL
Example::
import subhub
class Post(models.Model):
def save(self, **kwargs):
super(Post, self).save(**kwargs)
if self.published:
if transaction.is_managed():
transaction.commit()
topics = ['/blog/feed/'] # don't hardcode URLs, use 'reverse'
subhub.publish(
[absolute_url(t) for t in topics],
absolute_url(self.get_absolute_url()),
)
You can call "publish" from anywhere you find suitable. Just make sure that
before the call you commit a DB transaction if you use one. This is needed
because SubHub will make a separate HTTP request into your own server to fetch
an updated feed.
SubHub
======
SubHub is a Django application that implements a `PubSubHubBub`_ hub. Think
of it as a push mechanism that your personal site uses to notify subscribers
about changes in feeds that your site publishes.
.. note:: SubHub works only for Atom feeds. Which you should use anyway since
today there are no more reasons left to use actual RSS format for feeds.
This hub is not a standalone daemon that runs alongside your Django project.
It works as a library code sending notifications whenever you hit a "Publish"
button. It does, however, requires a cron job to process pending subscriptions
and failed notifications.
.. _PubSubHubBub: http://code.google.com/p/pubsubhubbub/
Installation
============
1. Install SubHub using your favorite package manager or simply with ``python
setup.py install``.
2. Include it "subhub" into INSTALLED_APPS in your Django settings and run
``./manage.py syncdb`` to create new tables.
3. Include SubHub urls into your project's urlconf under some sensible name::
urlpatterns = patterns('',
...
(r'^hub/', include('subhub.urls')),
)
4. Setup a cron job that will process pending subscriptions and distribute
failed notifications::
# Process subscriptions every 3 hours
0 */3 * * * user /path/to/manage.py subhub_maintenance --subscribe
# Distribute notifications every 15 minutes
*/15 * * * * user /path/to/manage.py subhub_maintenance --distribute
Announcing your hub
===================
In order to tell your potential subscribers that your feeds use PubSubHubBub
notifications you should include a link to a SubHub subscription view into
your Atom feeds. It looks a bit heavy but don't let it scare you off!
First thing to do is to subclass Django's built-in Atom feed generator and
teach it to look for hub links defined in your specific feed definitions::
from django.utils.feedgenerator import Atom1Feed
class HubAtom1Feed(Atom1Feed):
def add_root_elements(self, handler):
super(HubAtom1Feed, self).add_root_elements(handler)
hub_link = self.feed.get('hub_link')
if hub_link is not None:
handler.addQuickElement(u'link', '', {
u'rel': u'hub',
u'href': hub_link,
})
Then in each your feed for which you want to use notifications define a link::
from django.contrib.syndication import views
class MyBlogFeed(views.Feed):
feed_type = HubAtom1Feed
def feed_extra_kwargs(self, obj):
return {
'hub_link': absolute_url(reverse('subhub-hub')),
}
Chances are that you already have a function like ``absolute_url`` in your
project. It should make an URL absolute adding a scheme and a domain.
Publishing new and changed items
================================
To publish newly created or updated post you call function ``subhub.publish``
passing it two parameters:
- a list of feeds ("topics" in PubSubHubBub parlance) that this post appears in
- an entry_id for a post which in most cases is its absolute URL
Example::
import subhub
class Post(models.Model):
def save(self, **kwargs):
super(Post, self).save(**kwargs)
if self.published:
if transaction.is_managed():
transaction.commit()
topics = ['/blog/feed/'] # don't hardcode URLs, use 'reverse'
subhub.publish(
[absolute_url(t) for t in topics],
absolute_url(self.get_absolute_url()),
)
You can call "publish" from anywhere you find suitable. Just make sure that
before the call you commit a DB transaction if you use one. This is needed
because SubHub will make a separate HTTP request into your own server to fetch
an updated feed.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
SubHub-0.1.0.tar.gz
(9.0 kB
view details)
File details
Details for the file SubHub-0.1.0.tar.gz.
File metadata
- Download URL: SubHub-0.1.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac0247f2caeb400af88cb2b431890390c83775e673203a703968554f4f2cb431
|
|
| MD5 |
a7fb1c97e192b27accdba654c638efa0
|
|
| BLAKE2b-256 |
32192d26ba0b4127846c516ad7e1967ab71f2a102a280a5214b74ab2176d4054
|