【发布时间】:2015-02-25 13:12:27
【问题描述】:
我在做什么:
带有几个(10 到 15 个)固定提要的 RSS 阅读器。
问题:
当我在浏览器上点击刷新时,加载大约需要 15 秒。
我知道大部分加载时间是等待服务器遍历每个提要并加载每个提要中的所有条目。
也许 AJAX 可能是解决方案?
代码:
这是视图:
@app.route('/')
def index():
RSS_URLS = [
'http://feeds.feedburner.com/RockPaperShotgun',
'http://www.gameinformer.com/b/MainFeed.aspx?Tags=preview',
'http://www.polygon.com/rss/group/news/index.xml',
]
entries = []
for url in RSS_URLS:
entries.extend(feedparser.parse(url).entries)
entries_sorted = sorted(
entries,
key=lambda e: e.published_parsed,
reverse=True)
return render_template(
'index.html',
entries=entries_sorted
)
这是模板:
{% block content %}
<div class="row">
{% for e in entries %}
<div class="col-md-4 col-lg-3">
<h1><a href="{{ e.link }}">{{ e.title }}</a></h1>
<h5>Published on: {{ e.published }}</h5>
{% for content in e.content %}
<p>{{ content.value|safe }}</p>
{% else %}
<p>{{ e.summary_detail.value|safe }}</p>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}
【问题讨论】:
标签: python flask rss rss-reader feedparser