Created
June 17, 2014 19:10
-
-
Save mitchdowney/9cd4a3023fcc6ee5996e to your computer and use it in GitHub Desktop.
podcast.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Map feed information to Podcast | |
podcast.title = feed['title'] | |
podcast.description = feed['description'] | |
podcast.homepage = feed['homepage'] | |
if feed['keywords_list'] == '': | |
pass | |
else: | |
keywords_list = feed['keywords_list'] | |
# remove duplicates from keywords_list | |
# this unique_list method is not suited for long lists | |
ulist = [] | |
def unique_list(l): | |
for x in l: | |
keyword = x.term.lower() | |
if keyword not in ulist: | |
ulist.append(keyword) | |
return ulist | |
unique_list(keywords_list) | |
keywords = '' | |
for t in ulist: | |
keywords += t + ', ' | |
# remove the ', ' at the end of keywords string | |
podcast.keywords = keywords[:-2] | |
if feed['image_url'] == '': | |
pass | |
else: | |
image_url = feed['image_url'] | |
save_image_from_url(podcast, image_url, podcast.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PodcastSyndicationService(): | |
def obtain_podcast_information(self, uri): | |
# Potential future caching | |
# .parse can take more than just a uri. | |
# self._queue_episode_extraction(uri) | |
parsed_url = feedparser.parse(uri) | |
feed = parsed_url.feed | |
podcast_info = { | |
'title': feed.title, | |
} | |
if hasattr(feed, 'description'): | |
podcast_info['description'] = feed.description | |
else: | |
podcast_info['description'] = '' | |
if hasattr(feed, 'link'): | |
podcast_info['homepage'] = feed.link | |
else: | |
podcast_info['homepage'] = '' | |
if hasattr(feed, 'tags'): | |
podcast_info['keywords_list'] = feed.tags | |
else: | |
podcast_info['keywords_list'] = '' | |
if hasattr(feed, 'image.url'): | |
podcast_info['image_url'] = feed.image.url | |
else: | |
podcast_info['image_url'] = '' | |
return podcast_info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment