Skip to content

Instantly share code, notes, and snippets.

@mitchdowney
Created June 17, 2014 19:09
Show Gist options
  • Save mitchdowney/53dde6fc29b9b70d66f5 to your computer and use it in GitHub Desktop.
Save mitchdowney/53dde6fc29b9b70d66f5 to your computer and use it in GitHub Desktop.
podcast.py
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)
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