Fixed speed issue, no longer load each subreddit just to get the url.

This commit is contained in:
Michael Lazar
2015-01-22 23:24:24 -08:00
parent 8da813833f
commit b468a11fa8
9 changed files with 1719 additions and 7 deletions

View File

@@ -1,6 +1,15 @@
from datetime import datetime, timedelta
import textwrap
def strip_subreddit_url(permalink):
"""
Grab the subreddit from the permalink because submission.subreddit.url
makes a seperate call to the API.
"""
subreddit = clean(permalink).split('/')[4]
return '/r/{}'.format(subreddit)
def clean(unicode_string):
"""
Convert unicode string into ascii-safe characters.
@@ -106,7 +115,7 @@ class SubredditGenerator(object):
data['comments'] = '{} comments'.format(sub.num_comments)
data['score'] = '{} pts'.format(sub.score)
data['author'] = clean(sub.author.name)
data['subreddit'] = clean(sub.subreddit.url)
data['subreddit'] = strip_subreddit_url(sub.permalink)
data['url'] = ('(selfpost)' if is_selfpost(sub.url) else clean(sub.url))
return data