Commit 700ddcb8 by Matthew Mongeau

Store rss instead of parser in memcache.

parent a99ae175
......@@ -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)
......
<%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"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment