some live bugfixes

This commit is contained in:
Kyle Mahan 2015-04-18 22:35:31 +00:00
parent 24abdc076e
commit 398dd39929
8 changed files with 71 additions and 37 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ celerybeat-schedule*
config.py config.py
venv venv
*.egg-info *.egg-info
*.pyc

View file

@ -109,7 +109,7 @@ class Feed(db.Model):
last_pinged = db.Column(db.DateTime) last_pinged = db.Column(db.DateTime)
def get_feed_code(self): def get_feed_code(self):
return binascii.hexlify(self.feed.encode()) return self.feed # binascii.hexlify(self.feed.encode())
def get_or_create_push_secret(self): def get_or_create_push_secret(self):
if not self.push_secret: if not self.push_secret:

View file

@ -19,8 +19,8 @@ import sys
import time import time
import urllib.parse import urllib.parse
config = FlaskConfig('/home/kmahan/projects/woodwind') config = FlaskConfig('/srv/www/kylewm.com/woodwind')
config.from_pyfile('/home/kmahan/projects/woodwind.cfg') config.from_pyfile('woodwind.cfg')
# normal update interval for polling feeds # normal update interval for polling feeds
UPDATE_INTERVAL = datetime.timedelta(hours=1) UPDATE_INTERVAL = datetime.timedelta(hours=1)
@ -38,8 +38,6 @@ VIDEO_ENCLOSURE_TMPL = '<p><video class="u-video" src="{href}" controls '\
'preload=none ><a href="{href}">video</a></video></p>' 'preload=none ><a href="{href}">video</a></video></p>'
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
engine = sqlalchemy.create_engine(config['SQLALCHEMY_DATABASE_URI']) engine = sqlalchemy.create_engine(config['SQLALCHEMY_DATABASE_URI'])
@ -118,7 +116,9 @@ def update_feed(feed_id, content=None, is_polling=True):
for entry in result: for entry in result:
old = session.query(Entry)\ old = session.query(Entry)\
.filter(Entry.feed == feed)\ .filter(Entry.feed == feed)\
.filter(Entry.uid == entry.uid).first() .filter(Entry.uid == entry.uid)\
.order_by(Entry.id.desc())\
.first()
# have we seen this post before # have we seen this post before
if not old or not is_content_equal(old, entry): if not old or not is_content_equal(old, entry):
# set a default value for published if none is provided # set a default value for published if none is provided
@ -324,12 +324,12 @@ def process_xml_feed_for_new_entries(session, feed, content, backfill, now):
for link in p_entry.get('links', []): for link in p_entry.get('links', []):
if link.type == 'audio/mpeg': if link.type == 'audio/mpeg':
audio = AUDIO_ENCLOSURE_TMPL.format(href=link.get('href')) audio = AUDIO_ENCLOSURE_TMPL.format(href=link.get('href'))
content = audio + (content or '') content = (content or '') + audio
if (link.type == 'video/x-m4v' if (link.type == 'video/x-m4v'
or link.type == 'video/x-mp4' or link.type == 'video/x-mp4'
or link.type == 'video/mp4'): or link.type == 'video/mp4'):
video = VIDEO_ENCLOSURE_TMPL.format(href=link.get('href')) video = VIDEO_ENCLOSURE_TMPL.format(href=link.get('href'))
content = video + (content or '') content = (content or '') + video
entry = Entry( entry = Entry(
published=published, published=published,

View file

@ -32,9 +32,10 @@
{{ entry.author_name }} - {{ entry.author_name }} -
{% endif %} {% endif %}
{% if entry.feed %} {% if entry.feed %}
<a href="{{ url_for('.index', feed=entry.feed.get_feed_code()) }}"> <a href="{{ entry.feed.origin }}">{{ entry.feed.name }}</a>
{{ entry.feed.name }} <span style="font-size: 0.8em; float: right;">
</a> <a href="{{ url_for('.index', feed=entry.feed.get_feed_code()) }}">more from this feed</a>
</span>
{% endif %} {% endif %}
</header> </header>
{% if entry.title %} {% if entry.title %}
@ -49,6 +50,7 @@
<footer> <footer>
<a href="{{ entry.permalink }}">{{ entry.published | relative_time }}</a> <a href="{{ entry.permalink }}">{{ entry.published | relative_time }}</a>
<a href="{{ url_for('.index', entry=entry.permalink) }}" target="_blank">&#x21d7;</a>
{% if entry._syndicated_copies %} {% if entry._syndicated_copies %}
(also on{% for copy in entry._syndicated_copies %} <a href="{{ copy.permalink }}">{{ copy.permalink | domain_for_url }}</a>{% endfor %}) (also on{% for copy in entry._syndicated_copies %} <a href="{{ copy.permalink }}">{{ copy.permalink | domain_for_url }}</a>{% endfor %})

View file

@ -63,5 +63,6 @@
<main> <main>
{% block body %}{% endblock %} {% block body %}{% endblock %}
</main> </main>
{% block foot %}{% endblock %}
</body> </body>
</html> </html>

View file

@ -28,7 +28,7 @@
{% include '_entry.jinja2' with context %} {% include '_entry.jinja2' with context %}
{% endfor %} {% endfor %}
{% if entries %} {% if entries and has_older %}
<div class="pager"> <div class="pager">
<a id="older-link" href="{{ url_for_other_page(page=page+1) }}">Older</a> <a id="older-link" href="{{ url_for_other_page(page=page+1) }}">Older</a>
</div> </div>

View file

@ -10,9 +10,8 @@
{% block body %} {% block body %}
<p> <p>
<form style="display:inline;" <form action="{{ url_for('.update_all') }}" method="POST">
action="{{ url_for('.update_all') }}" method="POST"> <button type="submit">Poll All</button>
<button type="submit">Update All</button>
</form> </form>
</p> </p>
@ -22,28 +21,30 @@
<a href="{{ url_for('.index', feed=feed.get_feed_code()) }}">View only posts from this feed</a> <a href="{{ url_for('.index', feed=feed.get_feed_code()) }}">View only posts from this feed</a>
</div> </div>
<form style="display:inline" <form action="{{ url_for('.edit_feed') }}" method="POST">
action="{{ url_for('.edit_feed') }}" method="POST">
<input type="hidden" name="id" value="{{ feed.id }}"/> <input type="hidden" name="id" value="{{ feed.id }}"/>
<label>Name</label> <label>Name</label>
<input type="text" name="name" value="{{ feed.name }}"/> <input type="text" name="name" value="{{ feed.name }}"/>
<label>URL</label> <label>URL</label>
<input type="text" name="feed" value="{{ feed.feed }}"/> <input type="text" name="feed" value="{{ feed.feed }}"/>
<button type="submit">Save</button> <button type="submit">Save Edits</button>
</form> </form>
<form style="display:inline;"
action="{{ url_for('.update_feed') }}" method="POST"> <form action="{{ url_for('.update_feed') }}" method="POST">
<input type="hidden" name="id" value="{{ feed.id }}"/> <input type="hidden" name="id" value="{{ feed.id }}"/>
<button type="submit">Update</button> <button type="submit">Poll Now</button>
</form> </form>
<form style="display:inline;"
action="{{ url_for('.unsubscribe_feed') }}" method="POST"> <form action="{{ url_for('.unsubscribe_feed') }}" method="POST">
<input type="hidden" name="id" value="{{ feed.id }}"/> <input type="hidden" name="id" value="{{ feed.id }}"/>
<button type="submit">Unsubscribe</button> <button type="submit">Unsubscribe</button>
</form> </form>
<div class="feed-details">
<h4>Details</h4> <a class="show-details" data-target="details-{{loop.index}}" href="#">Show Details</a>
<div class="feed-details" id="details-{{loop.index}}">
<strong>Details</strong>
<ul> <ul>
<li>Last checked: {{feed.last_checked | relative_time}}</li> <li>Last checked: {{feed.last_checked | relative_time}}</li>
<li>Last updated: {{feed.last_updated | relative_time}}</li> <li>Last updated: {{feed.last_updated | relative_time}}</li>
@ -58,3 +59,20 @@
{% endfor %} {% endfor %}
{% endblock body %} {% endblock body %}
{% block foot %}
<script>
$(function() {
$(".feed-details").css({display: "none"});
$(".show-details").click(function(evt) {
evt.preventDefault();
var target = $(this).data("target");
$("#" + target).css({display: "inherit"});
$(this).css({display: "none"});
});
});
</script>
{% endblock foot %}

View file

@ -23,6 +23,7 @@ def index():
page = int(flask.request.args.get('page', 1)) page = int(flask.request.args.get('page', 1))
entries = [] entries = []
ws_topic = None ws_topic = None
has_older = True
if flask_login.current_user.is_authenticated(): if flask_login.current_user.is_authenticated():
per_page = flask.current_app.config.get('PER_PAGE', 30) per_page = flask.current_app.config.get('PER_PAGE', 30)
@ -36,24 +37,35 @@ def index():
.join(Feed.users)\ .join(Feed.users)\
.filter(User.id == flask_login.current_user.id) .filter(User.id == flask_login.current_user.id)
if 'feed' in flask.request.args: if 'entry' in flask.request.args:
feed_hex = flask.request.args.get('feed').encode() entry_url = flask.request.args.get('entry')
feed_url = binascii.unhexlify(feed_hex).decode('utf-8') entry = Entry.query.filter_by(permalink=entry_url)\
feed = Feed.query.filter_by(feed=feed_url).first() .order_by(Entry.retrieved.desc())\
if not feed: .first()
if not entry:
flask.abort(404) flask.abort(404)
entry_query = entry_query.filter(Feed.feed == feed_url) entries = [entry]
ws_topic = 'feed:{}'.format(feed.id) has_older = False
else: else:
ws_topic = 'user:{}'.format(flask_login.current_user.id) if 'feed' in flask.request.args:
#feed_hex = flask.request.args.get('feed').encode()
#feed_url = binascii.unhexlify(feed_hex).decode('utf-8')
feed_url = flask.request.args.get('feed')
feed = Feed.query.filter_by(feed=feed_url).first()
if not feed:
flask.abort(404)
entry_query = entry_query.filter(Feed.feed == feed_url)
ws_topic = 'feed:{}'.format(feed.id)
else:
ws_topic = 'user:{}'.format(flask_login.current_user.id)
entries = entry_query.order_by(Entry.retrieved.desc(), entries = entry_query.order_by(Entry.retrieved.desc(),
Entry.published.desc())\ Entry.published.desc())\
.offset(offset).limit(per_page).all() .offset(offset).limit(per_page).all()
entries = dedupe_copies(entries) entries = dedupe_copies(entries)
return flask.render_template('feed.jinja2', entries=entries, page=page, return flask.render_template('feed.jinja2', entries=entries, page=page,
ws_topic=ws_topic) ws_topic=ws_topic, has_older=has_older)
@views.route('/install') @views.route('/install')