Store rss instead of parser in memcache.

This commit is contained in:
Matthew Mongeau
2012-07-17 14:26:20 -04:00
parent 171e16f177
commit 384f24064e
2 changed files with 10 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import string
import sys
import uuid
import feedparser
import urllib
from django.conf import settings
from django.contrib.auth import logout, authenticate, login
@@ -47,13 +48,15 @@ def csrf_token(context):
def index(request):
''' Redirects to main page -- info page if user authenticated, or marketing if not
'''
feed_data = settings.RSS_URL if hasattr(settings, 'RSS_URL') else render_to_string("feed.rss", None)
feed = cache.get("students_index_rss_feed")
if feed == None:
feed = feedparser.parse(feed_data)
cache.set("students_index_rss_feed", feed, settings.RSS_TIMEOUT)
feed_data = cache.get("students_index_rss_feed_data")
if feed_data == None:
if hasattr(settings, 'RSS_URL'):
feed_data = urllib.urlopen(settings.RSS_URL).read()
else:
feed_data = render_to_string("feed.rss", None)
cache.set("students_index_rss_feed_data", feed_data, settings.RSS_TIMEOUT)
feed = feedparser.parse(feed_data)
entries = feed['entries'][0:3]
for entry in entries:
soup = BeautifulSoup(entry.description)

View File

@@ -1,5 +1,5 @@
<%namespace name='static' file='static_content.html'/>
<?xml version="1.0" encoding="UTF-8"?>
<%namespace name='static' file='static_content.html'/>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<id>tag:mitx.mit.edu,2012:/blog</id>
<link type="text/html" rel="alternate" href="http://mitx.mit.edu/blog"/>