look for link=hub/self in feed body in addition to http headers
This commit is contained in:
parent
6f2dc85110
commit
9842187266
3 changed files with 72 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
from config import Config
|
||||
from contextlib import contextmanager
|
||||
from woodwind.models import Feed, Entry
|
||||
import bs4
|
||||
import celery
|
||||
import celery.utils.log
|
||||
import datetime
|
||||
|
@ -135,6 +136,25 @@ def check_push_subscription(session, feed, response):
|
|||
hub = response.links.get('hub', {}).get('url')
|
||||
topic = response.links.get('self', {}).get('url')
|
||||
|
||||
if not hub or not topic:
|
||||
# try to find link rel elements
|
||||
if feed.type == 'html':
|
||||
soup = bs4.BeautifulSoup(get_response_content(response))
|
||||
if not hub:
|
||||
hub_link = soup.find('link', rel='hub')
|
||||
hub = hub_link and hub_link.get('href')
|
||||
if not topic:
|
||||
self_link = soup.find('link', rel='self')
|
||||
topic = self_link and self_link.get('href')
|
||||
elif feed.type == 'xml':
|
||||
parsed = feedparser.parse(get_response_content(response))
|
||||
if not hub:
|
||||
hub = next((link['href'] for link in parsed.feed.links
|
||||
if 'hub' in link['rel']), None)
|
||||
if not topic:
|
||||
topic = next((link['href'] for link in parsed.feed.links
|
||||
if 'self' in link['rel']), None)
|
||||
|
||||
if hub != old_hub or topic != old_topic or not feed.push_verified:
|
||||
feed.push_hub = hub
|
||||
feed.push_topic = topic
|
||||
|
@ -148,7 +168,6 @@ def check_push_subscription(session, feed, response):
|
|||
send_request('subscribe', hub, topic)
|
||||
|
||||
|
||||
|
||||
def is_content_equal(e1, e2):
|
||||
"""The criteria for determining if an entry that we've seen before
|
||||
has been updated. If any of these fields have changed, we'll scrub the
|
||||
|
|
|
@ -9,13 +9,18 @@
|
|||
{% endblock header %}
|
||||
|
||||
{% block body %}
|
||||
<form style="display:inline;"
|
||||
<p>
|
||||
<form style="display:inline;"
|
||||
action="{{ url_for('.update_all') }}" method="POST">
|
||||
<button type="submit">Update All</button>
|
||||
</form>
|
||||
<button type="submit">Update All</button>
|
||||
</form>
|
||||
</p>
|
||||
|
||||
{% for feed in feeds %}
|
||||
<article>
|
||||
<div>
|
||||
<a href="{{ url_for('.index', feed=feed.get_feed_code()) }}">View only posts from this feed</a>
|
||||
</div>
|
||||
|
||||
<form style="display:inline"
|
||||
action="{{ url_for('.edit_feed') }}" method="POST">
|
||||
|
@ -36,8 +41,18 @@
|
|||
<input type="hidden" name="id" value="{{ feed.id }}"/>
|
||||
<button type="submit">Unsubscribe</button>
|
||||
</form>
|
||||
<br/>
|
||||
<a href="{{ url_for('.index', feed=feed.get_feed_code()) }}">View posts from this feed</a>
|
||||
|
||||
<div class="feed-details">
|
||||
<h4>Details</h4>
|
||||
<ul>
|
||||
<li>Last checked: {{feed.last_checked | relative_time}}</li>
|
||||
<li>Last updated: {{feed.last_updated | relative_time}}</li>
|
||||
<li>PuSH hub: {{feed.push_hub}}</li>
|
||||
<li>PuSH topic: {{feed.push_topic}}</li>
|
||||
<li>PuSH verified: {{feed.push_verified}}</li>
|
||||
<li>PuSH last ping: {{feed.last_pinged | relative_time}}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ from .models import Feed, Entry, User
|
|||
import flask.ext.login as flask_login
|
||||
import binascii
|
||||
import bs4
|
||||
import datetime
|
||||
import feedparser
|
||||
import flask
|
||||
import mf2py
|
||||
|
@ -357,6 +358,37 @@ def favicon_for_url(url):
|
|||
return 'http://www.google.com/s2/favicons?domain={}'.format(parsed.netloc)
|
||||
|
||||
|
||||
@views.app_template_filter()
|
||||
def relative_time(dt):
|
||||
if dt:
|
||||
now = datetime.datetime.utcnow()
|
||||
diff = dt - now
|
||||
years = diff.days // 365
|
||||
hours = diff.seconds // 60 // 60
|
||||
minutes = diff.seconds // 60
|
||||
|
||||
if years > 1:
|
||||
return str(years) + ' years ago'
|
||||
if diff.days == 1:
|
||||
return 'A day ago'
|
||||
if diff.days > 1:
|
||||
return str(diff.days) + ' days ago'
|
||||
if hours == 1:
|
||||
return 'An hour ago'
|
||||
if hours > 1:
|
||||
return str(hours) + ' hours ago'
|
||||
if minutes == 1:
|
||||
return 'A minute ago'
|
||||
if minutes > 1:
|
||||
return str(minutes) + ' minutes ago'
|
||||
return str(diff.seconds) + ' seconds ago'
|
||||
|
||||
|
||||
@views.app_template_filter()
|
||||
def isoformat(dt):
|
||||
return dt and dt.isoformat()
|
||||
|
||||
|
||||
@views.app_template_filter()
|
||||
def add_preview(content):
|
||||
"""If a post ends with the URL of a known media source (youtube,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue