mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Refactoring updated urls in PuSH feeds.
This commit is contained in:
parent
dacd1941e6
commit
0fa19b2c75
2 changed files with 31 additions and 30 deletions
|
@ -110,7 +110,32 @@ class PushSubscription(models.Model):
|
|||
self.verify_token = token
|
||||
self.save()
|
||||
return token
|
||||
|
||||
def check_urls_against_pushed_data(self, parsed):
|
||||
if hasattr(parsed.feed, 'links'): # single notification
|
||||
hub_url = self.hub
|
||||
self_url = self.topic
|
||||
for link in parsed.feed.links:
|
||||
if link['rel'] == 'hub':
|
||||
hub_url = link['href']
|
||||
elif link['rel'] == 'self':
|
||||
self_url = link['href']
|
||||
|
||||
needs_update = False
|
||||
if hub_url and self.hub != hub_url:
|
||||
# hub URL has changed; let's update our subscription
|
||||
needs_update = True
|
||||
elif self_url != self.topic:
|
||||
# topic URL has changed
|
||||
needs_update = True
|
||||
|
||||
if needs_update:
|
||||
expiration_time = self.lease_expires - datetime.datetime.now()
|
||||
seconds = expiration_time.days*86400 + expiration_time.seconds
|
||||
PushSubscription.objects.subscribe(
|
||||
self_url, feed=self.feed, hub=hub_url,
|
||||
lease_seconds=seconds)
|
||||
|
||||
def __unicode__(self):
|
||||
if self.verified:
|
||||
verified = u'verified'
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# Adapted from djpubsubhubbub. See License: http://git.participatoryculture.org/djpubsubhubbub/tree/LICENSE
|
||||
|
||||
from datetime import datetime
|
||||
import feedparser
|
||||
|
||||
from django.http import HttpResponse, Http404
|
||||
|
@ -33,35 +32,12 @@ def push_callback(request, push_id):
|
|||
elif request.method == 'POST':
|
||||
subscription = get_object_or_404(PushSubscription, pk=push_id)
|
||||
parsed = feedparser.parse(request.raw_post_data)
|
||||
if parsed.feed.links: # single notification
|
||||
hub_url = subscription.hub
|
||||
self_url = subscription.topic
|
||||
for link in parsed.feed.links:
|
||||
if link['rel'] == 'hub':
|
||||
hub_url = link['href']
|
||||
elif link['rel'] == 'self':
|
||||
self_url = link['href']
|
||||
subscription.check_urls_against_pushed_data(parsed)
|
||||
updated.send(sender=subscription, update=parsed)
|
||||
|
||||
needs_update = False
|
||||
if hub_url and subscription.hub != hub_url:
|
||||
# hub URL has changed; let's update our subscription
|
||||
needs_update = True
|
||||
elif self_url != subscription.topic:
|
||||
# topic URL has changed
|
||||
needs_update = True
|
||||
# subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
|
||||
# Don't give fat ping, just fetch.
|
||||
subscription.feed.queue_pushed_feed_xml("Fetch me")
|
||||
|
||||
if needs_update:
|
||||
expiration_time = subscription.lease_expires - datetime.now()
|
||||
seconds = expiration_time.days*86400 + expiration_time.seconds
|
||||
PushSubscription.objects.subscribe(
|
||||
self_url, feed=subscription.feed, hub=hub_url,
|
||||
callback=request.build_absolute_uri(),
|
||||
lease_seconds=seconds)
|
||||
|
||||
# subscription.feed.queue_pushed_feed_xml(request.raw_post_data)
|
||||
# Don't give fat ping, just fetch.
|
||||
subscription.feed.queue_pushed_feed_xml("Fetch me")
|
||||
|
||||
updated.send(sender=subscription, update=parsed)
|
||||
return HttpResponse('')
|
||||
return HttpResponse('')
|
||||
return Http404
|
||||
|
|
Loading…
Add table
Reference in a new issue